I am using the following code to HTTPS post an xml file to third party server. Now I believe I am able to send the file correctly but I need to pass a HTML input field value of type hidden as well with it. If I use a simple HTML interface as shown below I am successful:
<form enctype="multipart/form-da
ta" action="
https://myurl" method="POST">
<input type="hidden" name="MyFieldName" value="myvalue">
<input type="file" name="Myfile">
<br/>
<input type="submit">
</form>
I want to simulate the exact thing in my .NET code. I am confused how to pass value of the hidden field MyFieldName along with the file as I am using the WebClient.UploadFile() function. I tried passing it as query string but it does not work.
Can you please suggest something, I am now desperate.
Following is the code i am using at the moment in .NET:
Private Sub testHTTPPostXmlDoc()
Try
Dim web As New System.Net.WebClient()
web.Headers.Add("Content-T
ype", "multipart/form-data")
' Simulating the line <input type="hidden" name="MyFieldName" value="myvalue">
web.QueryString.Add("MyFie
ldName", "myvalue")
Dim res As Byte() = web.UploadFile("
https://myurl", "POST", "C:\MyFile.xml")
Dim response As String = System.Text.Encoding.ASCII
.GetString
(res)
Catch webEx As WebException
MsgBox(webEx.Message, MsgBoxStyle.Information, "Debug Msg")
MsgBox(webEx.StackTrace, MsgBoxStyle.Information, "Debug Msg")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "Debug Msg")
MsgBox(ex.StackTrace, MsgBoxStyle.Information, "Debug Msg")
End Try
End Sub
I BELIEVE THE ISSUE IS BECAUSE OF THE SSL CERTIFICATE. AS I AM POSTING TO HTTPS RATHER THAN HTTP, I THINK I NEED TO ENCRYPT THE DATA SOMEHOW.
CAN YOU PLEASE ASSIST. AS WHEN I DO POST FROM HTML PAGE IT WORKS FINE BUT I BELIEVE THE WEB BROWSER ENCRYPTS THE DATA REQUESTING THE CERTIFICATE PUBLIC KEY. HOW CAN I IMPLEMENT THE SAME IN MY CODE?