Solved

HTTP Requests

Posted on 2003-11-14
2
257 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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