Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

HTTP Post

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-27-2007, 09:46 PM
Junior Member
 
Join Date: Jun 2007
Posts: 38
Default HTTP Post

I need to Post some long data to our webserver and I need the server to parse the data as Post variables. Using the HTTP library, I can send GET data easily by appending the variables to the URL (ex. url.php?var1=Y&var2=N).

Since I have some long data that really can't get sent via the GET method, how can I easily send data using the POST method? I have seen the way the tutorial uses the PUT method and reading from a file, but I am not uploading a file. I just need to send data pairs to the server as POST variables.

In a normal HTML page, the form would look like this:
<form>
<input type="hidden" name="var1" value="Y">
<input type="hidden" name="var2" value="N">
<input type="submit" value="submit">
</form>

How can I accomplish the same thing with PPC?

Here is what I have now, but it doesn't work:

**********************
Request.New1("http://www.url.com") 'Build the request.
Request.Method = "POST"
Request.TimeOut = 30000 '30 seconds
Response.New1

Writer.New1(Request.GetStream,true)
Writer.WriteString("<input type='hidden' name='tet' value='im alive'>")
Response.Value = Request.GetResponse 'Call the server
result = Response.GetString 'Get the string from the response stream.
Response.Close
************************

Thanks for all the help. You guys are great!
Reply With Quote
  #2 (permalink)  
Old 06-28-2007, 01:01 AM
Junior Member
 
Join Date: Jun 2007
Posts: 38
Default

I figured it out. Simple solutions can sometimes take forever to find! Here is the solution, just in case anyone wants to know:

*********************
Response.New1
Request.New1(URL)
Request.Method = "POST"
Request.ContentType = "application/x-www-form-urlencoded"
bin.New1(Request.GetStream,true) 'Use a BinaryFile object to write the data to the Request stream.
bin.WriteString("var1=Y&var2=N")
Response.Value = Request.GetResponse
result = Response.GetString
Response.Close
msgbox(result)
**************************

The content-type was required. With that in place, just write the variables in name=value pairs to the GetStream using the BinaryFile library. The webserver you post to will reconize them as posted variables, accessible by the name assigned to the variable.

The page on my webserver (in PHP) just returns the variables that are posted:

<?php
foreach($_POST as 4p=>$v){
echo $p." - ".$v;
}
?>
Reply With Quote
  #3 (permalink)  
Old 06-28-2007, 01:27 AM
Junior Member
 
Join Date: Jun 2007
Posts: 38
Default

One other note:

For some reason, a weird character is placed in front of the GetStream. I guess this may be something that gets written to start the file? Anyway, a quick fix (since it is late and I am getting tired) is to just put a dummy variable at the start of your name/value pairs (ex. bin.WriteString("dummyvar=2&var1=Y&var2=N")). Then just ignore the first dummy variable and move on to the good ones!
Reply With Quote
  #4 (permalink)  
Old 07-07-2007, 04:36 PM
rmh rmh is offline
Newbie
 
Join Date: Jul 2007
Posts: 8
Default

The example GET code in the help works OK for me using URL variables but I also need to send volume data and having struggled with this for some time, I discover the code below works on pc but -not- on device.... (WM5)

I get a response, but no data is sent.

this is using BinaryFile.dll version 1.2

Sub Globals

End Sub

Sub App_Start
Form1.Show
Response.New1
Request.New1(URL)
Request.Method = "POST"
Request.ContentType = "application/x-www-form-urlencoded"
bin.New1(Request.GetStream,true) 'Use a BinaryFile object to write the data to the Request stream.
st="var1=z&var2=hullo world2"
bin.WriteString(st)
Response.Value = Request.GetResponse
result = Response.GetString
Response.Close
msgbox(result)
End Sub
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP POST error message miataman Questions (Windows Mobile) 10 07-11-2008 10:28 AM
HTTP POST error Elrick Bug Reports 3 05-24-2008 02:06 PM
HTTP Post fails if Umlauts sent and UTF-8 is used TWELVE Questions (Windows Mobile) 11 04-29-2008 10:13 AM
HTTP POST on Device - error message TWELVE Questions (Windows Mobile) 6 04-26-2008 09:35 AM
HTTP Post nsidney Questions (Windows Mobile) 4 01-30-2008 09:52 AM


All times are GMT. The time now is 04:46 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0