Rabbit80
asked on
http POST in Visual Basic
I am trying to learn how to perorm a http POST from within a VB application. The idea is to upload a file (which will be PDF) and get back a result which i then use later.
The upload url is http://server/webservices/upload.php
Required info is Filename and SessionID both of which I know.
How do I do this in Visual Basic 2008?
The upload url is http://server/webservices/upload.php
Required info is Filename and SessionID both of which I know.
How do I do this in Visual Basic 2008?
ASKER
thanks, these links are helping. The problem I am facing at the moment is that I am getting a "session not specified" error message. I dont know where and how to add this info. I have created a Session_ID (There was a mistake in my first post - needs the underscore) using SOAP, but I now need to pass this back to the upload.php along with filename and the binary data.
I dont understand fully how the POST syntax is constructed - is there any chance you could show me what the completed POST that I send should look like?
I dont understand fully how the POST syntax is constructed - is there any chance you could show me what the completed POST that I send should look like?
ASKER
If it helps, the following link is the source for the uploads.php script;
http://docs.knowledgetree.com/api/__filesource/fsource_KTWEBSERVICE__ktwebserviceupload.php.html
http://docs.knowledgetree.com/api/__filesource/fsource_KTWEBSERVICE__ktwebserviceupload.php.html
hmm.. So are do you have a page, with no login, and you are wanting to use the sessionID to uniquely identify the user? If so, I don't think sessionID's are unique for all time.
I guess I am thinking ASP/ASP.NET when you say session ID. IS this an ASP.NET (vb.net) app, or just a plain Windows Forms Vb.net app?
I guess I am thinking ASP/ASP.NET when you say session ID. IS this an ASP.NET (vb.net) app, or just a plain Windows Forms Vb.net app?
ASKER
Let me try to explain what i am trying to do...
Using the KnowledgeTree Open Source DMS, i need to write an app that will allow me to upload files in bulk. I am using Visual Basic 2008 Express to try to achieve this.
From the documentation, I am told that this requires a two-step process.
"The web service exposes two sets of add_document(). 1) a two phase add_document. It requires an http post to upload the initial document followed by the web service call to add_document" - I won't mention the 2nd option since it is not suitable.
"Webservices/upload.php
This requires the following post parameters:
documentname
sessionid "
Note: the above information is apparantly wrong - the requirements are actually named "action" and "session_id". This can be checked on the above link to the php.
The first thing I do with my program is connect to the webservice via the SOAP interface and authenticate. This returns a SessionID.
I have also performed sucessfully the second part of the webservices - the add_document function which also uses the SessionID, but this can be done via http GET and is relatively easy.
The upload.php should create a temporary copy of the file and return a filename which is used by the add_document function - i have tested add_document by manually creating the temporary file and using add_document to process it.
What I cant get a grasp on is exactly what the upload.php requires to be uploaded - where exactly do I put the session_id and action(documentname)? It is the structure of HTTP POST that I dont understand. Imagine I am uploading HelloWorld.txt which contains "Hello World" - what would the entire HTTP POST look like? Just substitue my SessionID key with xxx's and i will get the idea!
Thanks for your time!
Using the KnowledgeTree Open Source DMS, i need to write an app that will allow me to upload files in bulk. I am using Visual Basic 2008 Express to try to achieve this.
From the documentation, I am told that this requires a two-step process.
"The web service exposes two sets of add_document(). 1) a two phase add_document. It requires an http post to upload the initial document followed by the web service call to add_document" - I won't mention the 2nd option since it is not suitable.
"Webservices/upload.php
This requires the following post parameters:
documentname
sessionid "
Note: the above information is apparantly wrong - the requirements are actually named "action" and "session_id". This can be checked on the above link to the php.
The first thing I do with my program is connect to the webservice via the SOAP interface and authenticate. This returns a SessionID.
I have also performed sucessfully the second part of the webservices - the add_document function which also uses the SessionID, but this can be done via http GET and is relatively easy.
The upload.php should create a temporary copy of the file and return a filename which is used by the add_document function - i have tested add_document by manually creating the temporary file and using add_document to process it.
What I cant get a grasp on is exactly what the upload.php requires to be uploaded - where exactly do I put the session_id and action(documentname)? It is the structure of HTTP POST that I dont understand. Imagine I am uploading HelloWorld.txt which contains "Hello World" - what would the entire HTTP POST look like? Just substitue my SessionID key with xxx's and i will get the idea!
Thanks for your time!
I will have to look at that tomorrow. I wonder if expects XML or something.
ASKER
I have used the code below as a starting point for my HTTP POST. This accepts the session_ID and action - I just need some help in actually uploading the file. xFileName contains a path to the file i.e. "C:\test.pdf"
Help!!!
Thanks
Help!!!
Thanks
Public Shared Function PostData(ByVal Session_ID As String, ByVal xFileName As String, ByVal URL As String, Optional ByVal NeedResponse As Boolean = True) As String
Dim ReturnPage As String = String.Empty
Dim Uri As New Uri(URL)
Dim xSession
Dim Req As HttpWebRequest
Req = CType(WebRequest.Create(URL), HttpWebRequest)
Req.Method = "Post"
Req.ContentType = "application/x-www-form-urlencoded"
xSession = "&session_id=" + Session_ID + "&action=C"
Dim sw As New StreamWriter(Req.GetRequestStream)
sw.Write(xSession)
sw.Close()
sw.Dispose()
If NeedResponse Then
Dim sr As New StreamReader(Req.GetResponse.GetResponseStream)
ReturnPage = sr.ReadToEnd
sr.Close()
sr.Dispose()
End If
Req.GetResponse.Close()
Return ReturnPage
End Function
I'm currently on vacation so it will be at least Wed. before I will be taking hard looks at this questions. Sorry.
ASKER
No problem - I was away for a week which is why it got left for a while! Do you know of any good books or websites describing the format for HTTP POST? in particular sending binary data and form data in a multipart post - it is still the structure of the POST that i am struggling to understand.
Do these help?
http://joel.net/code/easyhttp.aspx
http://forums.msdn.microsoft.com/en-US/netfxnetcom/thread/575e043a-ec46-459b-9e38-b2cdf9759a7e/
Download a binary file:
http://www.eggheadcafe.com/community/aspnet/14/79979/async-http-post-to-downlo.aspx
Send multipart in C#
http://www.codeproject.com/KB/cs/multipart_request_C_.aspx
http://joel.net/code/easyhttp.aspx
http://forums.msdn.microsoft.com/en-US/netfxnetcom/thread/575e043a-ec46-459b-9e38-b2cdf9759a7e/
Download a binary file:
http://www.eggheadcafe.com/community/aspnet/14/79979/async-http-post-to-downlo.aspx
Send multipart in C#
http://www.codeproject.com/KB/cs/multipart_request_C_.aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
https://www.experts-exchange.com/questions/23075741/Using-HTTP-POST.html
http://www.example-code.com/vbdotnet/http_post_simple.asp