Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
hey,

a 3rd party gave me an http request trace dump sent from a black berry device:
POST /maveo1 HTTP/1.1
Host: au1.blahblah.com.au:6226
Connection: close
User-Agent: mView1/4.3.0
Content-Length: 26
Command=SNAP&Timestamp=0


the code at black berry is : (code updated)
HttpConnection httpConnection = (HttpConnection) Connector.open("http://" + _thrdOwner.getWebServiceURLforViewerAccount());
      httpConnection.setRequestMethod(HttpConnection.POST);
      httpConnection.setRequestProperty("User-Agent", "mView/4.3.0 (Blackberry OS)");

      out = httpConnection.openOutputStream();
      String sCommand = command1.toString() + "&" + command2.toString() + "="
          + value1.toString() + "" + value2.toString() + "\r\n";

      out.write(sCommand.getBytes());
      out.flush(); // This forces the POST to happen

      responseCode = httpConnection.getResponseCode();


and asking me to send above http request on a button click on a web page to trigger some command, when I ask them can they give me a uri or web service path etc. They say what we have send is enough.

I tried doing the below and it worked: (Code Updated)

HttpWebRequest myHttpWebRequest =(HttpWebRequest)WebRequest.Create("http://au1.blahblah.com.au:6226/maveo1");
             myHttpWebRequest.Method = "POST";
      myHttpWebRequest.UserAgent = "mView/4.5.0";

      string postData = "Command=SNAP&Timestamp=0\n";
      ASCIIEncoding encoding = new ASCIIEncoding ();
      byte[] byte1 = encoding.GetBytes (postData);
      myHttpWebRequest.ContentLength = byte1.Length;
      Stream newStream = myHttpWebRequest.GetRequestStream ();
      newStream.Write (byte1, 0, byte1.Length);
      newStream.Close ();
      WebResponse resp = myHttpWebRequest.GetResponse();


so i reproduced the http reques like below:

POST /maveo/ HTTP/1.1

Host: au1.blahblah.com.au:6226

Content-Length: 24

Expect: 100-continue



HTTP/1.1 100 Continue

server: m-View HTTP Service/4.5.0.12

date: Tue, 07 Jun 2011 17:38:25 GMT



Command=SNAP&Timestamp=0HTTP/1.1 200 OK

server: m-View HTTP Service/4.5.0.12

date: Tue, 07 Jun 2011 17:38:25 GMT

connection: close


Now y the http post is saying 'Expect: 100-continue' can we get rid of it...
Posted
Updated 7-Jun-11 16:27pm
v5

1 solution

I noticed your code does not specify HttpWebRequest.Method, with must be "POST", according to your HTTP dump which you're trying to reproduce.

[EDIT]
Answering a follow-up question:
The use of "Expect: 100-continue" is explained in the text of HTTP standard here:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html[^].

I don't think you need to "get rid of it" :-).

—SA
 
Share this answer
 
v2
Comments
saxenaabhi6 7-Jun-11 2:01am    
I did put the method "POST", page do flicker a little bit... but i can't see any request when i trace the network of the page using developer bar on IE.
when i debug the code i also see an exception thrown on my Stream variable saying: "This Stream does not support Seek Operations".
i picked this from here
Sergey Alexandrovich Kryukov 7-Jun-11 4:14am    
OK, sure. Where do you use Seek? Catch exception and dump Exception.Stack to see where it propagates...
--SA
Sergey Alexandrovich Kryukov 7-Jun-11 4:16am    
Also, where do you read from resp?
--SA
saxenaabhi6 7-Jun-11 6:52am    
i got the stream problem solved and able to get request going but I don't know y its 'Expect: 100-continue'. I updated my question.
Sergey Alexandrovich Kryukov 7-Jun-11 16:14pm    
Please see my update (after [EDIT]).
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900