How to make Http request using WIP Soft


#1

Hi all, i am facing the problem that my application couldn’t retrieve the data from webpage that i wanted.
i am using wipsoft to enable my device to connect to the GPRS network. so i write my code like this (it is just a part from the code that related to the TCP client function handler). this function runs whenever i tried to send data (in my case i tried to send a HTTP GET request to a web server).

void ClientEventHandler (wip_event_t *Event, void *ctx)
{
	u32 Read;
	u32 Write;
	ascii *DataBuffer;
	ascii writeBuffer[30];

	adl_atSendResponse (ADL_AT_UNS, "\r\nInside the TCP Handler\r\n");

	switch (Event->kind)
	{
	case WIP_CEV_READ:															//Triggered when the data received by the remote 
		adl_atSendResponse (ADL_AT_UNS, "\r\nInside the WIP_CEV_READ\r\n");		//server is ready to read
		int nread;
		
		nread = wip_read (Channel, rcv_buffer + rcv_offset, sizeof( rcv_buffer) - rcv_offset);
		if( nread < 0) 
		{ 
			adl_atSendResponse (ADL_AT_UNS, "[SAMPLE] read error \n");
			return;
		}
		rcv_offset += nread;

	    if( rcv_offset == sizeof( rcv_buffer)) 
		{	
			adl_atSendResponse (ADL_AT_UNS,"[SAMPLE] Reception capacity exceeded, won't read more\r\n");
		}							
		if (nread >0)
		{
			adl_atSendResponse (ADL_AT_UNS, rcv_buffer);						//send the data read to the external application
			adl_atSendResponse (ADL_AT_UNS,"\r\n");
		}
		else if (nread == 0)
		{
			adl_atSendResponse (ADL_AT_UNS,"read finished\r\n");						//triggered when the reading process failed
		}
		break;
	
	case WIP_CEV_OPEN:															//triggered when the the Client Socket is connected 
		adl_atSendResponse (ADL_AT_UNS,"\r\ninside WIP_CEV_OPEN\r\n");			//to the remote server
		adl_atSendResponse (ADL_AT_UNS,"\r\nClient is COnnected\r\n");
		break;

	case WIP_CEV_WRITE:															//Triggered when the writing process to the  
		adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_WRITE\r\n");		//channel is completed
		Write = wip_write(Channel, "GET http://www.okkykusuma.gofreeserve.com/socket.php HTTP/1.0\r\n",66); //Saving the data into the Write buffer			
		wm_itoa (Write,writeBuffer);											//Convert the return value of the writing process into ascii
		adl_atSendResponse (ADL_AT_UNS,writeBuffer);							//Send the return value into Hyper Terminal
		adl_atSendResponse (ADL_AT_UNS,"\r\n");							
		break;
	
	case WIP_CEV_ERROR :														//Triggered when the connecting to remote server
		adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_ERROR\r\n");		//is failed 
		break;

	case WIP_CEV_PEER_CLOSE :													//Triggered when the CLient Socket is closed
		adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_PEER_CLOSE\r\n");
		break;

	}
}

but the result from running this function is like this

OK

Inside the TCP Handler

inside WIP_CEV_OPEN

Client is COnnected

Inside the TCP Handler

inside the WIP_CEV_WRITE
38

Inside the TCP Handler

Inside the WIP_CEV_READ
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>403 Forbidden</TITLE>
</HEAD><BODY>
<H1>Forbidden</H1>
You don't have permission to access /
on this server.<P>
<P>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.
</BODY></HTML>


Inside the TCP Handler

inside the WIP_CEV_PEER_CLOSE
IP address -> 10.233.87.64

Any idea of what have been wrong? my guess is that my application had succesfully access the internet but there is something wrong with the HTTP GET request that i wrote. but i’ve been trying to change the request and the results is still the same. I will be really glad if there is someone who could show me some clue or suggestion regarding this problem.

Best Regards,
Okky Kusuma


#2

A silly question, but one has to ask it : did you try to enter the url into your web browser and check if what you get on screen is really what you expected ? At first sight, I’d say, according to your result, that the server is sending you back some error page, probably because it couldn’t execute the PHP script and not because it failed to send you datas…

Another point : in the HTTP Get request, you count 66 characters. Shouldn’t it be 63 ? i believe \r and \n only count as 1 character, not 2…

Regards,
Christophe.


#3

I don’t think so.


#4

Not at all - it is an absolutely basic one!

Yes, that is certainly the first thing that should be tried!

Remember that an HTTP server is just implementing the standard HTTP protocol - so it neither knows nor cares what particular client was used to create the requests that it receives.

Yes, that is certainly the case!

The specific error being given is HTTP 403 - Forbidden.
That means that it has received your request, and it knows what you’re asking for, and it is refusing to give it to you because you are not allowed to have it!

So the next thing that should be tried is to use a tool such as Fiddler to examine the exact request that your Browser is sending, and ensure that your WIP application is doing precisely the same…

fiddler2.com/fiddler2/

Also be sure to have a copy of the HTTP spec to hand - jmarshall.com/easy/http/#httpspec - and read this tutorial:
jmarshall.com/easy/http/


#5

That’s not what an HTTP GET request should look like - see: jmarshall.com/easy/http/#sample

and read the rest of that tutorial!


#6

Hiya,

That’s my understanding as well. I believe that the GCC C compiler parses these character literals into single characters.

According to the C standard (ISO/IEC 9899:TC2 Committee Draft — May 6, 2005 WG14/N1124):

5.2.2 Character display semantics
1 The active position is that location on a display device where the next character output by
the fputc function would appear. The intent of writing a printing character (as defined
by the isprint function) to a display device is to display a graphic representation of
that character at the active position and then advance the active position to the next
position on the current line. The direction of writing is locale-specific. If the active
position is at the final position of a line (if there is one), the behavior of the display device
is unspecified.
2 Alphabetic escape sequences representing nongraphic characters in the execution
character set are intended to produce actions on display devices as follows:
\a (alert) Produces an audible or visible alert without changing the active position.
\b (backspace) Moves the active position to the previous position on the current line. If
the active position is at the initial position of a line, the behavior of the display
device is unspecified.
\f ( form feed) Moves the active position to the initial position at the start of the next
logical page.
\n (new line) Moves the active position to the initial position of the next line.
\r (carriage return) Moves the active position to the initial position of the current line.
\t (horizontal tab) Moves the active position to the next horizontal tabulation position
on the current line. If the active position is at or past the last defined horizontal
tabulation position, the behavior of the display device is unspecified.
\v (vertical tab) Moves the active position to the initial position of the next vertical
tabulation position. If the active position is at or past the last defined vertical
tabulation position, the behavior of the display device is unspecified.
3 Each of these escape sequences shall produce a unique implementation-defined value
which can be stored in a single char object. The external representations in a text file
need not be identical to the internal representations, and are outside the scope of this
International Standard.

Regardless, as awneil notes, this is not the way to create a HTTP get request. See this thread on how to look at the HTTP GET sample provided by Wavecom.

ciao, Dave
ciao, Dave


#7

wow it’s really helpful. i haven’t checked all the link that you gave me. but i will! and for the question have i checked my web page using web browser, the answer is yes and the result is perfect. but it was in a browser. the result was different when i tried using wavecom. i should follow the instruction that awneil had sent me. Thank you for the advices.

best regards,
Okky Kusuma


#8

I think that’s the key.

It is certainly the case that some systems translate “\n” to CRLF in the output stream - but the string itself contains only LF.

See, for example: viewtopic.php?f=38&t=3024&p=11153&hilit=translation#p11153

As far as HTTP is concerned, CRLF is a two-character sequence.

See: viewtopic.php?f=21&t=149&p=6043&hilit=crlf#p6043


#9

Thank you! the problem is solved after 2 days of depression. HAHAHAHA… the problem is like what dave and awneil had said before. the HTTP request format is wrong. so i follow the link that awneil gave me. and followed the insctruction and it worked. but after that some more problem occured. i only send my request once, but why the response is always more then 1? like this :

at+tcpclient="www.okkykusuma.gofreeserve.com","80"
at

OK

Inside the TCP Handler

inside WIP_CEV_OPEN

Client is COnnected

Inside the TCP Handler

inside the WIP_CEV_WRITE
119

Inside the TCP Handler

Inside the WIP_CEV_READ
no-cache
Content-Type: text/html
X-Cache: MISS from demil1.byetcluster.com
X-Cache-Lookup: MISS from demil1.byetcluster.com:80
Via: 1.1 demil1.byetcluster.com:80 (Lusca/LUSCA_1.0)
Connection: close

#ini harga pisang#ud#per kg : Rp 9000#ud#Harga bangkwang#ud#Per kg : Rp 8000#ud###end#HTTP/1.1 200 OK
Date: Tue, 02 Jun 2009 08:18:36 GMT
Server: Apache
Cache-Control: no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform
Expires: Tue, 02 Jun 2009 08:18:36 GMT
Vary: Accept-Encoding,User-Agent
Pragma: no-cache
Content-Type: text/html
X-Cache: MISS from demil1.byetcluster.com
X-Cache-Lookup: MISS from demil1.byetcluster.com:80
Via: 1.1 demil1.byetcluster.com:80 (Lusca/LUSCA_1.0)
Connection: close

f

Inside the TCP Handler

Inside the WIP_CEV_READ
no-cache
Content-Type: text/html
X-Cache: MISS from demil1.byetcluster.com
X-Cache-Lookup: MISS from demil1.byetcluster.com:80
Via: 1.1 demil1.byetcluster.com:80 (Lusca/LUSCA_1.0)
Connection: close

#ini harga pisang#ud#per kg : Rp 9000#ud#Harga bangkwang#ud#Per kg : Rp 8000#ud###end#HTTP/1.1 200 OK
Date: Tue, 02 Jun 2009 08:18:36 GMT
Server: Apache
Cache-Control: no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform
Expires: T

does anyone have a clue??

Best regards, hade