473,395 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

XML post via HTTPS

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.Su bstring(i,
payload.Length-i)));
// break;
// }
// UrlEncoded.Append(HttpUtility.UrlEncode(payload.Su bstring(i,
j-i)));
// UrlEncoded.Append(payload.Substring(j,1));
// i = j+1;
// }
//UrlEncoded.Append(HttpUtility.UrlDecode(payload.Su bstring(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();

}
}
Nov 18 '05 #1
0 868

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ing. Angel León | last post by:
http://wedoit4you.com/forums4you/display_message.php?Msg_pk_id=628 /** Author: Ing. Angel Leon Function: postHttps($url,$params) Given the full URL of the Target and The Params it will...
11
by: brendan | last post by:
Sorry this isnt a cross post .. i just didnt get any help from alt.php. I have a website which utilises post forms for navigation in some areas. Problem is, when *some* users hit the BACK button...
2
by: Angie | last post by:
Hello everybody, I have an osCommerce shopping cart on my site, which is an open-source product that uses php. I'm very new to php. I also have an online scheduling application that I outsourced...
6
by: DavidT | last post by:
I need to build a valid XML file using ASP form elements, pass that "file" to a https url and then retrieve the ID that is returned. I can build the XML into a string no problem but how then heck...
1
by: Dave Brown | last post by:
I am attempting to post to a url (https://FakeURL/logon.asp) using the HttpWebRequest class. The response for a succesful post will contain the html for the logon user's default page. We've...
0
by: mahesh anasuri | last post by:
Hi all, I am new to this mailing list. Thankful if any one is using curl/linux version to and worked on Https. I have created certificates (PEM format) for client and server using openSSL. I...
3
by: Yourself | last post by:
Hi, I'm trying to post data to PayPal for a shopping cart, basically I want to replicate a form like the following, but create the variables dynamically from code behind: <form...
3
by: assaf | last post by:
(warning Python newbie) I'm trying to use Python to work with del.icio.us's API. Basically, I need to be able to do a simple https post, with username/password authentication. (For those...
2
by: Arti | last post by:
Hi, I am trying to access a servlet hosted on Tomcat server using HTTPS Post protocol. I am getting the exception: "The underlying connection was closed: Could not establish trust relationship...
0
by: shlim | last post by:
Currently I'm using VB.Net to perform a http/https multipart form post to a servlet. I'm able to perform the post using HttpWebrequest via GetRequestStream(). However, the servlet returned me with...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.