0

I already have an existing application implemented using java in app engine....now i want to connect this servlet from c# forms program ?,...this is the tried out code for request

HttpWebRequest authRequest = (HttpWebRequest)HttpWebRequest.Create(googleLoginUrl);
byte[] buffer = Encoding.ASCII.GetBytes(postData);
authRequest.ContentLength = buffer.Length;
 Stream postDataStr=authRequest.GetRequestStream();
postDataStr.Write(buffer, 0, buffer.Length);
postDataStr.Close();

now it is connected to the GSE(Google Servlet Engine)...i want a response for this....how to implement that?

user123456789
  • 77
  • 1
  • 12

1 Answers1

1

You just need to read the response:

HttpWebResponse response = (HttpWebResponse)authRequest.GetResponse ();
Console.WriteLine ("Content length is {0}", response.ContentLength);
Console.WriteLine ("Content type is {0}", response.ContentType);
string raw_html = (new StreamReader(response.GetResponseStream()).ReadToEnd();

You can see further examples from: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse.aspx

Note: I believe since you're posting data you'll also have to set your authRequest as a POST via:

authRequest.Method = "POST";
JoshVarty
  • 9,066
  • 4
  • 52
  • 80
  • what does this raw_html contain? – user123456789 Jan 28 '13 at 05:42
  • It should contain the result of your HttpWebRequest in string form. If you're making requests to a web server, it will likely be HTML. If you're making requests to an API of some sort, it could be XML or JSON. You could always print it to the Console and see exactly what the response looks like. – JoshVarty Jan 28 '13 at 05:47
  • it looks like some kind of random letters...that doesnot give any meaning..the request that im sending is a HTTP request to upload files..what to do? – user123456789 Jan 28 '13 at 06:03
  • If you need to upload files, you should look at the answer to this question: http://stackoverflow.com/questions/566462/upload-files-with-httpwebrequest-multipart-form-data – JoshVarty Jan 28 '13 at 06:24
  • ya but i want to write a web request to download the file...can that be done? – user123456789 Jan 28 '13 at 06:40
  • Yes absolutely. If the URL you're using is the correct URL for the file, the reason the "raw_html" variable has random letters in it is because it's trying to convert the raw file to text format. Instead save the file somewhere. Here's an example: http://social.msdn.microsoft.com/Forums/en/vssmartdevicesvbcs/thread/b489fe1d-a237-48ac-b58a-f901e1b03bde – JoshVarty Jan 28 '13 at 06:47
  • how to access the file using the url??.can you help...this is all new to me and that forum is difficult to understand – user123456789 Jan 28 '13 at 07:08
  • the raw_html doesnt show the url...it shows null when displayed in messagebox...how to get the correct URL? – user123456789 Jan 28 '13 at 09:01