By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,640 Members | 2,355 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,640 IT Pros & Developers. It's quick & easy.

How to post an XML file to HTTPS using vb.net 2005

P: n/a
JD
I am currently trying to send an XML document to an HTTPS address. The
address is something like https://blah.com:5558/test/http.

I am trying to use httpWebRequest but am not sure if this is the correct
way. My code looks like the following:

Private Sub Upload(ByVal fileName As String, ByVal uploadUrl As String)
Dim requestStream As Stream = Nothing
Dim fileStream As FileStream = Nothing
Dim uploadResponse As HttpWebResponse = Nothing
Try
Dim uploadRequest As HttpWebRequest = WebRequest.Create(uploadUrl)
uploadRequest.Method = WebRequestMethods.Http.Post

' UploadFile is not supported through an Http proxy
' so we disable the proxy for this request.
uploadRequest.Proxy = Nothing

requestStream = uploadRequest.GetRequestStream()
fileStream = File.Open(fileName, FileMode.Open)

Dim buffer(1024) As Byte
Dim bytesRead As Integer
While True
bytesRead = fileStream.Read(buffer, 0, buffer.Length)
If bytesRead = 0 Then
Exit While
End If
requestStream.Write(buffer, 0, bytesRead)
End While

' The request stream must be closed before getting the response.
requestStream.Close()

uploadResponse = uploadRequest.GetResponse()
Console.WriteLine("Upload complete.")
Catch ex As UriFormatException
Console.WriteLine(ex.Message)
Catch ex As IOException
Console.WriteLine(ex.Message)
Catch ex As WebException
Console.WriteLine(ex.Message)

Finally
If uploadResponse IsNot Nothing Then
uploadResponse.Close()
End If
If fileStream IsNot Nothing Then
fileStream.Close()
End If
If requestStream IsNot Nothing Then
requestStream.Close()
End If
End Try

When this code is executed, the following exception occurs:

The remote server returned an error: (401) Unauthorized.

Another method I tried also returns an error :
The remote server returned an error:(501) Not
Implemented.system.net.webexception

Any help / advise would be greatly appreciated.
Cheers
JD
Mar 23 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Hi JD

Did you manage to get your code working. I'm trying to do a similar
thing and having difficulties, the same 401 exception.

It would be a great help if anybody could shed some light on the
situation

Thanks in advance

g

--
the_g_man
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message2225194.html

Jun 29 '06 #2

P: n/a

Hi,

I have done something like this in C# (below) im posting it for you. might
be helpfull :)...

Cheers

private String SendDa(string url, string keyword)
{
String result="";
String strPost="your xml string from a file";
StreamWriter myWriter=null;
HttpWebRequest objRequest=(HttpWebRequest)WebRequest.Create("Your URL
Here");
objRequest.Method="POST";
objRequest.ContentLength=strPost.Length;
objRequest.ContentType="application/x-www-form-urlencoded";

try
{
myWriter=new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(strPost);
}
catch(Exception ex)
{
return ex.Message;
}
finally
{
yWriter.Close();
}

HttpWebResponse objResponse=(HttpWebResponse)objRequest.GetRespons e();
using (StreamReader sr=new StreamReader(objResponse.GetResponseStream()))
{
result=sr.ReadToEnd();
sr.Close();
}
return result;
}
}
--
Waqas Ahmed
Project Manager/Lead Developer
Softflux Pakistan
"the_g_man" wrote:

Hi JD

Did you manage to get your code working. I'm trying to do a similar
thing and having difficulties, the same 401 exception.

It would be a great help if anybody could shed some light on the
situation

Thanks in advance

g

--
the_g_man
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message2225194.html

Jul 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.