HTTP POST error message

miataman

Member
Licensed User
Hi,
My program on the device display error during the request http :
"An error message cannot
be displayed because an
optional resource assembly
containing it cannot be
found
Continue?"


(On the desktop it's OK no display error).

My device under framework 2
My project included objects ->
Request:Webrequest
Response:Webresponse

my code :

Response.new1
Request.new1("http://wwwmyserver.com/upload.php?lat="&lat)
Response.value=Request.Getresponse
Res=Response.GetString
Response.close

thanks for help !
stef
:confused:
 

miataman

Member
Licensed User
thanks Agraham

my code for request http does not work :

error An unexpected error occurred on a send
continue?

i'm checking....
 

TWELVE

Active Member
Licensed User
From Googling around I think this means that the server closed the TCP connection.
- He might wanna try a different server to exclude issues with a particular server.

- different headers might be used for troubleshooting ( TRACE header for example would instruct the server to return the packets you sent to it).
In case of issues with the http i would not start with POST, because that's the most difficult.Instead he should try a GET first to see how the server answers.

- a network sniffer like WireShark might be used to figure out where the problem is very quickly - if one is familar with the usage of these tools.
For me a sniffer is the first choice because i can see what's going on there immediatly.


Engels Rajangam : The underlying connection was closed... This article suggests that setting WebRequest.KeepAlive to false might help with this sort of error - it defaults to true.
KeepAlive is integral part of the HTTP1.1 protocol.Therefore it is always enabled with HTTP 1.1, in contrast to 1.0, where the KeepAlive had to be enabled explicitly.Most servers support 1.1, so this is certainly not the cause of the issue.

As i already said above, POST is not a good point to start with.Once a GET is working, this would be the proof that the routines work in general and the internet connection is ok.One could then proceed to test with POST headers.

From my personal experience ( i also do a lot with these POSTs on the device)
i would say, the error message mean, there is either a problem with the internet connection itself, the server connection ( does not accept the connection) or the DNS name resolution.

I also use an errorhandler in my http send routine and whenever the errorhandler traps an error this means i do not have established an internet connection.Therefore i use this as indicator whether the connection is there or not ( due to lack of description of the error - i do not use your new library yet which returns descriptions ...;-) )


kind regards

TWELVE
 
Last edited:

kawawong

Member
Licensed User
Hi, TWELVE,

Can you share some routine of using POST method? I want to submit some data to the web server, and the string is very large and cannot use the GET method (it works).

I am looking for code snippet for doing this using http.dll.

For example, i want to submit two set of text with name a and b. In the server side, I have a php script which use $_POST['a'] and $_POST['b'] to read these 2 data. I am now have problem of how to pass these two parameter in basic4ppc.

Tks in advance.

Cheers.
Kawawong
 

Erel

Administrator
Staff member
Licensed User
You will need something like:
B4X:
Sub Globals
Dim buffer(0) As byte
End Sub
Sub App_Start
    bit.New1 'bit is a Bitwise object
    postdate
End Sub
Sub PostDate
    Response.New1
    Request.New1("http://www...")
    request.ContentType = "application/x-www-form-urlencoded"
    request.Method = "POST"
    writer.New1(request.GetStream,false)
    s = "a=value1&b=23"
    buffer() = bit.StringToBytes(s,0,StrLength(s))
    writer.WriteBytes(buffer())
    response.Value = request.GetResponse
    Msgbox(response.GetString)
    response.Close
End Sub
 

Cableguy

Expert
Licensed User
my code :

Response.new1
Request.new1("http://wwwmyserver.com/upload.php?lat="&lat)
Response.value=Request.Getresponse
Res=Response.GetString
Response.close


:confused:
If this code is correct, the then error is a simple dot(.) missing after www....
 

kawawong

Member
Licensed User
Tks.

Since I have a large text required to post to the server, is there any function like

urlencode

to encode the text first before POSTing it?

:sign0085: ^_^
 
Top