XML post via HTTPS

M

Mallya

All,
I am trying to post XML data to https site and try to get repsonce in
XML

- I think i am wrting XMl to the site properly.
- But the at server side - the message format is wrong (thats what
server side people claim)

Here is the working example in vb script (TS is transaction in XML

Set xObj = CreateObject("SomeObject")
xObj.AddHeader "Referer","YourCompanyName"
xObj.AddHeader "Accept","image/gif, image/jpeg, image/pjpeg,
text/plain, text/html, */* "
xObj.AddHeader "Content-Type","image/gif"
xObj.AddHeader "Content-Length",cStr(len(TS))
xObj.port = 443
strResult = xObj.Retrieve("https://servername",
Request_POST, TS, "", "")


Here what I tried in .NET
and when i do req.GetResponse(), I get 500 error. ( the comment lines
shows what all i tried)


thanks
mallya

======================================================================


public string Subscribe(String payload)
{

HttpWebResponse result = null;
StringBuilder responce = new StringBuilder();


try
{

System.Net.HttpWebRequest req = (HttpWebRequest)
WebRequest.Create(url);
req.Method = "POST";
req.KeepAlive = false;
req.Referer = "My company";
//req.Accept = "image/gif, image/jpeg,image/pjpeg, text/plain,
text/html, */*";
req.Accept = "image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, */*";

//req.ContentType = "image/gif";
req.ContentType = "text/xml; charset=\"utf-8\"";
//req.ContentType = "text/xml";
//req.ContentType = "application/x-www-form-urlencoded";



//req.ContentType = "application/x-www-form-urlencoded";


StringBuilder UrlEncoded = new StringBuilder();
Char[] reserved = {'?', '=', '&'};
byte[] SomeBytes = null;

if (payload != null)
{
// int i=0, j;
// while(i<payload.Length)
// {
// j=payload.IndexOfAny(reserved, i);
// if (j==-1)
// {
// UrlEncoded.Append(HttpUtility.UrlEncode(payload.Substring(i,
payload.Length-i)));
// break;
// }
// UrlEncoded.Append(HttpUtility.UrlEncode(payload.Substring(i,
j-i)));
// UrlEncoded.Append(payload.Substring(j,1));
// i = j+1;
// }
//UrlEncoded.Append(HttpUtility.UrlDecode(payload.Substring(0,
payload.Length)));
UrlEncoded.Append(payload);
SomeBytes = Encoding.UTF8.GetBytes(UrlEncoded.ToString());
//req.ContentLength = SomeBytes.Length;
req.AllowWriteStreamBuffering = true;
Stream newStream = req.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.Length);
newStream.Close();
}
else
{
req.ContentLength = 0;
}

//
//
// Char[] reserved = {'?', '=', '&'};
// byte[] SomeBytes = null;
//
// SomeBytes = Encoding.UTF8.GetBytes(xml);
//
// req.ContentLength = SomeBytes.Length;
// Stream newStream = req.GetRequestStream();
// newStream.Write(SomeBytes, 0, SomeBytes.Length);
// newStream.Close();

result = (HttpWebResponse) req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader sr = new StreamReader( ReceiveStream, encode );
Console.WriteLine("\r\nResponse stream received");
Char[] read = new Char[256];
int count = sr.Read( read, 0, 256 );
Console.WriteLine("HTML...\r\n");

while (count > 0)
{
String str = new String(read, 0, count);
Console.Write(str);
responce.Append(str);
count = sr.Read(read, 0, 256);
}
Console.WriteLine("");
}
catch(Exception e)
{
Console.WriteLine( e.ToString());
Console.WriteLine("\r\nThe request URI could not be found or was
malformed");
}
finally
{
if ( result != null )
{
result.Close();
}
}

return responce.ToString();

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top