?
Solved

HTTPS POST USING WEBCLIENT

Posted on 2007-04-01
4
Medium Priority
?
10,922 Views
Last Modified: 2012-06-21
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-data" 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-Type", "multipart/form-data")
           
            ' Simulating the line <input type="hidden" name="MyFieldName" value="myvalue">
web.QueryString.Add("MyFieldName", "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?
0
Comment
Question by:imranbuchh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Author Comment

by:imranbuchh
ID: 18862119
Hello,

Its a 500 point question .. Pump your points .. Need help...

I checked when i use my browser a digital certificate gets saved in the browser certificates as it is an https url. Do i need to export that certificate from my browser and use it somehow ... Any ideas ...

Cheers,
Imran.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 2000 total points
ID: 18872806
<ou have to add your MyFieldName=myvalue to the POST's body (separated by a & if you already have data there)

(sorry don't know the proper syntax for .net)
0

Featured Post

WatchGuard's M Series Appliances - Miecom Approved

WatchGuard's newest M series appliances were put to the test by Miercom.  We had great results and outperformed all of our competitors in both stateless and stateful traffic throghput scenarios! Ready to see how your UTM appliance stacked up? Download the Miercom Report!

Question has a verified solution.

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

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

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