|
-
Jan 10th, 2006, 02:58 PM
#1
Thread Starter
Fanatic Member
https post and retreive URL
We are currently working with a 3rd party site where we need to post a
URL to their site, and retreive a URL. The URL looks something like this:
https://site.com/x.aspx?fieldname=va...eldname2=value
and the response will look similar. Is there a way to post and read these values without actually having them appear in the address bar, as some of the information will be private?
-
Jan 10th, 2006, 04:24 PM
#2
Thread Starter
Fanatic Member
Re: https post and retreive URL
Oh also, I know there used to be a limit on URL size for a GET post, is it still 255 characters?
-
Jan 10th, 2006, 04:45 PM
#3
Re: https post and retreive URL
You can use XMLHTTP to perform a GET. This will post the values to the page.
http://15seconds.com/issue/050526.htm
-
Jan 10th, 2006, 07:37 PM
#4
Thread Starter
Fanatic Member
Re: https post and retreive URL
We might be able to use a simple Response.Redirect. My only concern is that the length of the URL will be extremely long. Is there a limit?
-
Jan 10th, 2006, 08:08 PM
#5
Re: https post and retreive URL
The limit depends on the browser I belive.
I googled and found this link: http://www.asp101.com/tips/index.asp?id=102
The amount of data you can transfer on the QueryString is limited by a number of factors, but the one that seems to be the most restrictive is the space in your browser's address bar. The Internet Explorer versions 5 and 6 that I tested only allowed up to 2,047 characters while Netscape Navigator version 4 seemed to be able to handle up to 30,000 and I couldn't get version 6 much past 9,000.
And another page said 5000 in IE 5.5.
HIH
HoraShadow
-
Jan 10th, 2006, 08:14 PM
#6
Re: https post and retreive URL
And the way I would do it is use System.Net.HttpWebRequest and System.Net.HttpWebResponse to query and get the result.
You can make the request Post or Get and then save the stream in the web response object.
Look into them. They are very nice.
HIH
HoraShadow
-
Jan 11th, 2006, 10:42 AM
#7
Thread Starter
Fanatic Member
Re: https post and retreive URL
Could you post some code on how to do that? I've never really used those objects that way.
-
Jan 11th, 2006, 12:30 PM
#8
Re: https post and retreive URL
Import System.Net
VB Code:
Dim tempHttpWebRequest As HttpWebRequest
Dim tempHttpWebResponse As HttpWebResponse
Dim queryString as string = "http://www.google.com"
Dim username as string = "user"
Dim password as string = "pass"
Dim myAuth As String = String.Format("{0}:{1}", username, password)
Dim myBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(myAuth)
Dim my64BytesHeader As String = Convert.ToBase64String(myBytes)
'creates the request
tempHttpWebRequest = CType(WebRequest.Create(queryString), HttpWebRequest)
tempHttpWebRequest.Method = "GET"
tempHttpWebRequest.Headers.Add("Authorization", "basic " & my64BytesHeader)
Dim myStream As IO.Stream = tempHttpWebRequest.GetRequestStream
'Sends the data.
myStream.Write(postInformationByteArray, 0, postInformationByteArray.Length)
myStream.Close()
tempHttpWebResponse = CType(tempHttpWebRequest.GetResponse, HttpWebResponse)
'saves the response in a buffer
Dim tempStream As IO.Stream = tempHttpWebResponse.GetResponseStream()
Dim inBuf(100000) As Byte
Dim bytesToRead As Integer = CInt(inBuf.Length)
Dim bytesRead As Integer = 0
While bytesToRead > 0
Dim n As Integer = tempStream.Read(inBuf, bytesRead, bytesToRead)
If n = 0 Then
Exit While
End If
bytesRead += n
bytesToRead -= n
End While
'writes the buffer into file
Dim tempFileStream As New IO.FileStream("httpWebRequest.txt", IO.FileMode.CreateNew, IO.FileAccess.Write)
tempFileStream.Write(inBuf, 0, bytesRead)
tempStream.Close()
tempFileStream.Close()
tempFileStream = Nothing
This code does all the work. Just change the querystring for yours, username and password, in case the web server requieres authentification. It should be pretty straight forward, and does everything.
It ends up saving the response on a txt file. You have to grab it before and process the information. The txt file is for demostration only.
Hope it helps
HoraShadow
Last edited by HoraShadow; Jan 11th, 2006 at 01:43 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|