Solved

HTTP Requests

Posted on 2003-11-14
2
258 Views
Last Modified: 2010-04-16
Hi,

I need to be able to post some data using and HTTP request to an SMS gateway.  How do I do this in .Net?  I have found the same old sample on 10000s of sites where you can grab and display a web site - but thats not what I need.

An example of the request that needs to be sent:

--------------------------------------------------

POST /SOMESPECIFIEDDIR.sms HTTP/1.1
HOST: the.url.com
CONTENT-LENGTH: CONTENTLENGTH

XmlMsg=ENCODEDDATA

--------------------------------------------------

I'm guessing this is a simple job as its simple enough in PHP.



PS here's that same old sample I keep finding.
------------------------------------------------------
WebRequest smsRequest = HttpWebRequest.Create(uri);
smsRequest.Method = "POST";
                  
WebResponse smsResponse = smsRequest.GetResponse();
StreamReader smsStream = new System.IO.StreamReader(smsResponse.GetResponseStream());
                  
return smsStream.ReadToEnd();
0
Comment
Question by:dpwdc
2 Comments
 
LVL 10

Accepted Solution

by:
ptmcomp earned 80 total points
ID: 9749315
Stream requestStream = smsRequest.GetRequestStream();
StreamWriter requestWriter = new StreamWriter(requestStream, Encoding.UTF8 /* or whatever you need */);
requestWriter.WriteLine("XmlMsg=ENCODEDDATA"); // this is sent as POST data

or if it's in the Header:

smsRequest.Headers.Add("XmlMsg=ENCODEDDATA"); // this is sent in the header
0
 
LVL 1

Author Comment

by:dpwdc
ID: 9949859
close enough.  i worked it out.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question