POST request

Aspire89

Member
Licensed User
Hello, help with a problem.

use the code:

B4X:
Request.New1 ( "http://www.tumblr.com/api/write") 
 Request.Method = "POST" 
 Request.KeepAlive = True 
 Request.ContentType = "application / x-www-form-urlencoded" 
stream.New1 (Request.GetStream, True) 
 name = "email = mail & password = pass"
stream.WriteBytes (stream.StringToBytes (name)) 
 Response.New1 
 Request.GetAsyncResponse
looked request header :
POST / api / write HTTP/1.1
Content-Type: application / x-www-form-urlencoded
Host: Tumblr
Content-Length: 107
Expect: 100-continue
Connection: Keep-Alive

on that server is responsible:
417 Expectation Failed
The expectation given in the Expect request-header
field could not be met by this server.
The client sent
Expect: 100-continue
but we only allow the 100-continue expectation.

How to fix that does not send Expect?

Thanks.
 

agraham

Expert
Licensed User
Try this using the Door library. It will only work on .NET 2.0 on a device (if it works at all!). Obj1 is a Door library Object.
B4X:
Obj1.New1(False)
...   
Request.New1(URL)
Obj1.FromLibrary (Request, "req", B4PObject(2))
Obj1.Value = Obj1.GetProperty("ServicePoint")
Obj1.SetPproperty("Expect100Continue", False)
...
 

Aspire89

Member
Licensed User
Thank you again helps. It turns door.dll very useful library, but you need to know how to use it.​
 

Aspire89

Member
Licensed User
use code:
B4X:
    response.New1
    Obj1.New1(False)
    request.New3("http://twitter.com/statuses/update.xml",tbUser.Text,tbPass.Text)
    
    Obj1.FromLibrary ("Main.Request", "req", B4PObject(2))
    Obj1.Value = Obj1.GetProperty("ServicePoint")
    Obj1.SetProperty("Expect100Continue", False)    

    request.Method = "POST"
    request.TimeOut = 30000

    writer.New1(Request.GetStream,False) 
    Parameters = "status=" & tbStatus.Text
    writer.WriteBytes(writer.StringToBytes(Parameters))
    Response.Value = Request.GetResponse 
    temp = Response.GetString 
    Response.Close
    Msgbox(temp)
on the desktop works fine on device error: NullReferenceException, with it not even trying to connect to the Internet, help me please understand.
 

agraham

Expert
Licensed User
It took a lot of headscratching until I noticed this small sentence in MSDN for the ServicePoint property of a HttpWebRequest.
Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE Platform Note: This property is null until the request is sent because of the additional network transmission required.
So unfortunately it looks like this won't work on a device :(
 

Aspire89

Member
Licensed User
Thanks for the info, it's sad that it will not work on devices, I grieved very much and wanted to write a client for Twitter.
 

agraham

Expert
Licensed User
but you might try to use the ServicePointManager class
That's what the Door library code I posted above does - and it works on the desktop. The problem is that on the device the ServicePoint is not actually assigned until GetResponse is called and then it is too late. The actual C# code in the SubmitResponse method of HttpWebRequest on the device is
B4X:
...
 ServicePoint point = ServicePointManager.FindServicePoint(this.m_url, setProxy);
    this.[COLOR="Red"]m_srvPoint [/COLOR]= point;[COLOR="Green"] // ServicePoint assigned[/color]
    this.prepareHeaders();
    this.m_requestSent = true;
    if (this.m_boundConnection != null)
    {
        this.m_boundConnection.m_srvPoint = point;
        this.m_boundConnection.[COLOR="red"]submitRequest[/COLOR](this);[COLOR="Green"] // send request[/COLOR]
    }
    else
    {
        point.SubmitRequest(this, this.GetConnectionGroupLine());
    }
and there is no way to get in the middle to play with the ServicePoint.
 

agraham

Expert
Licensed User
No, I can't see a way to do it in Basic4ppc although I am not very good on Http stuff - maybe someone else has a suggestion.
 

Erel

Administrator
Staff member
Licensed User
I think that changing the static property of ServicePointManager should solve it:
B4X:
    obj1.New1(False)
    obj1.CreateNew("System.Net.ServicePointManager" & obj1.System_NS)
    obj1.SetProperty("Expect100Continue", False)
@Aspire89 can you please try it?
 

Erel

Administrator
Staff member
Licensed User
On the desktop works on the device I get an error:
Response code: -1
ReceiveFailure
Do you think that it is related to the Expect header? Can you see the actual request in the server logs?
 

Aspire89

Member
Licensed User
Do you think that it is related to the Expect header? Can you see the actual request in the server logs?
Log from the server can not see, but HttpAnalyzer see the sent and received information.

On the desktop, sent:
B4X:
POST /statuses/update.xml HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: Basic QXNwaXJlODk6Njc2OTg5MjYx
Host: twitter.com
Content-Length: 10

status=111
receive:
B4X:
HTTP/1.1 200 OK
Date: Wed, 26 Aug 2009 16:12:50 GMT
Server: hi
Last-Modified: Wed, 26 Aug 2009 16:12:50 GMT
Status: 200 OK
ETag: "95c29f721eb3a3158c936ef3c316ef91"
Pragma: no-cache
Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
Content-Type: application/xml; charset=utf-8
Content-Length: 1721
Expires: Tue, 31 Mar 1981 05:00:00 GMT
X-Revision: d480fb2179a9d77a12d84649a8cddb7781039783
X-Transaction: 1251303170-18736-3013
Set-Cookie: lang=en; path=/
Set-Cookie: lang=en; path=/
Set-Cookie: _twitter_sess=BAh7CjoTcGFzc3dvcmRfdG9rZW4iLWUzMWQzMzIxMzYzNjViODZmNjE2Zjdh%250AMWE4MmUxNjE1ZGY2MDZmZmM6CXVzZXJpBHf6BwE6DGNzcmZfaWQiJWQyZjUx%250AOGMzYmYzM2I4ZDBiOGI1YTA1NGI4MzA0YTNkOgdpZCIlODQwYzA4NjU1NWI1%250ANDE0MzFlN2Y0MWJhYTdiN2JjMGYiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xs%250AZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA%253D--14a75279178086f72163ae85166f5b7f5e650a0d; domain=.twitter.com; path=/
Vary: Accept-Encoding
Connection: close

<?xml version="1.0" encoding="UTF-8"?>
<status>
  <created_at>Wed Aug 26 16:12:50 +0000 2009</created_at>
  <id>3559064512</id>
  <text>111</text>
  <source>&lt;a href=&quot;http://apiwiki.twitter.com/&quot; rel=&quot;nofollow&quot;&gt;API&lt;/a&gt;</source>
  <truncated>false</truncated>
  <in_reply_to_status_id></in_reply_to_status_id>
  <in_reply_to_user_id></in_reply_to_user_id>
  <favorited>false</favorited>
  <in_reply_to_screen_name></in_reply_to_screen_name>
  <user>
    <id>17300087</id>
    <name>Aspire89</name>
    <screen_name>Aspire89</screen_name>
    <location></location>
    <description></description>
    <profile_image_url>http://a1.twimg.com/profile_images/69905926/535_normal.jpg</profile_image_url>
    <url>http://aspire89.tumblr.com/</url>
    <protected>false</protected>
    <followers_count>17</followers_count>
    <profile_background_color>1A1B1F</profile_background_color>
    <profile_text_color>666666</profile_text_color>
    <profile_link_color>2FC2EF</profile_link_color>
    <profile_sidebar_fill_color>252429</profile_sidebar_fill_color>
    <profile_sidebar_border_color>181A1E</profile_sidebar_border_color>
    <friends_count>25</friends_count>
    <created_at>Tue Nov 11 01:34:00 +0000 2008</created_at>
    <favourites_count>0</favourites_count>
    <utc_offset>18000</utc_offset>
    <time_zone>Ekaterinburg</time_zone>
    <profile_background_image_url>http://s.twimg.com/a/1250809294/images/themes/theme9/bg.gif</profile_background_image_url>
    <profile_background_tile>false</profile_background_tile>
    <statuses_count>70</statuses_count>
    <notifications>false</notifications>
    <verified>false</verified>
    <following>false</following>
  </user>
</status>
The device sent:
B4X:
POST /statuses/update.xml HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: twitter.com
Authorization: Basic QXNwaXJlODk6Njc2OTg5MjYx
Content-Length: 10
Connection: Keep-Alive

status=222
receive:
B4X:
HTTP/1.1 403 Forbidden
Date: Wed, 26 Aug 2009 16:18:50 GMT
Server: hi
Last-Modified: Wed, 26 Aug 2009 16:18:50 GMT
Status: 403 Forbidden
Pragma: no-cache
Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
Content-Type: application/xml; charset=utf-8
Content-Length: 168
Expires: Tue, 31 Mar 1981 05:00:00 GMT
X-Revision: d480fb2179a9d77a12d84649a8cddb7781039783
X-Transaction: 1251303530-21871-6900
Set-Cookie: lang=en; path=/
Set-Cookie: lang=en; path=/
Set-Cookie: _twitter_sess=BAh7CjoJdXNlcmkEd%252FoHAToMY3NyZl9pZCIlMDlkYTQyMjczOTljZmIwODY3%250AMjUzNTI0Y2I1ZGZiNWU6B2lkIiUxN2FlODljNGU0ZjBiYmUyZjIzOGIwMjBl%250AZmZmOTViYSIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZs%250AYXNoSGFzaHsABjoKQHVzZWR7ADoTcGFzc3dvcmRfdG9rZW4iLWUzMWQzMzIx%250AMzYzNjViODZmNjE2ZjdhMWE4MmUxNjE1ZGY2MDZmZmM%253D--53c13ea08f2dede40de256e75be5d0efcd0a0d6d; domain=.twitter.com; path=/
Vary: Accept-Encoding
Connection: close

<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <request>/statuses/update.xml</request>
  <error>Client must provide a 'status' parameter with a value.</error>
</hash>
And yet, if run on an emulator, an error Response code: 403 Forbiden, but on the device Response code: 408 Request Timeout
 

Erel

Administrator
Staff member
Licensed User
Why is the status 222 on the desktop and 111 on the device?
 
Top