Android Question HTTP

Noorul HAQUE

Member
Licensed User
Dear All

I am working on small project where my app need to update some data on my php/ mysql server.

http://www.xxxxx.com/datafeed.php?uid=0506891234&type=11&ans=312312lo38971289l

when I type this links from my browser its work as it designed, but if use

with okHttpUtils2 and following code its not working, please help me on this.

Dim GetIMEI As HttpJob
GetIMEI.Initialize("GetIMEI", Me)
GetIMEI.PostString("http://www.xxxxx.com/datafeed.php?uid=0506891234&type=11&ans=312312lo38971289l

Sub JobDone (Job As HttpJob)
If Job.Success = True Then
Job.Release
Else
Log(Job.ErrorMessage)
End If
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
1. Use code tags when posting code!
2. Do you expect to get help if you HIDE the LOG from us?
3. I guess you should not use PostString. Instead you should use job.download
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
The first example, if you type it into your browser, will issue an HTTP GET command.
The second is explicitly requesting to use the HTTP POST command.

Also, with PostString you specify the link and the params separately, so it should be

B4X:
GetIMEI.PostString("http://www.xxxxx.com/datafeed.php", "uid=0506891234&type=11&ans=312312lo38971289l")
http://www.xxxxx.com/datafeed.php?uid=0506891234&type=11&ans=312312lo38971289l
If the second isn't working, then the server-side PHP script is expecting only to receive updates via GET. That's not necessarily a problem, just that as Don says, you need to use job.download to get the results, but if you do have control over the script it's worth taking a look at it and seeing how easy it is to adapt it to accept information via POST.

It may be as simple as referring to the variables in the script using the PHP global $_REQUEST, for instance $_REQUEST['uid] instead of $_GET['uid'] - the request array will have the values regardless of whether or not they were set using GET or POST. However, if there are bits in the script that check how it was called eg

B4X:
if ( $_SERVER['REQUEST_METHOD'] == 'GET' )

then you'll have to do a bit more work.

Personally, if I'm writing scripts that will be called this way, I almost always make sure they work with POST rather than GET (or with both) these days:

1. If you're also building an HTML/JS interface, it's a lot easier to send data via POST using jQuery
2. You can check the REQUEST_METHOD as above to determine if you're updating data, or just retrieving it
3. When you use GET, the query string will appear in server logs. That doesn't happen with POSTed data

Point three is particularly important if there's anything sensitive about the data - ie it could be linked to a person, or a user id, or a device id - and even more so if you're using shared hosting, where other people may be able to see the server logs. Even without a shared server, it could still be an issue, as URLs requested on some networks (for example, corporate networks, or even some ISP cache servers) may log the requested URLs
 
Upvote 0

Noorul HAQUE

Member
Licensed User
Thanks Manfred and nwhitfield ......

I used download
method and its working.... thanks Manfred

nwhitfield really appreciating your effort to make me understanding on the conceptual level, and your explanation method really taken me long way back to my college days, one of my professor explanation method was same...
 
Upvote 0
Top