Results 1 to 8 of 8

Thread: https post and retreive URL

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    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?

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    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?

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    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?

  5. #5
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    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

  6. #6
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    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

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    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.

  8. #8
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Re: https post and retreive URL

    Import System.Net

    VB Code:
    1. Dim tempHttpWebRequest As HttpWebRequest
    2. Dim tempHttpWebResponse As HttpWebResponse
    3.  
    4. Dim queryString as string = "http://www.google.com"
    5. Dim username as string = "user"
    6. Dim password as string = "pass"
    7.  
    8. Dim myAuth As String = String.Format("{0}:{1}", username, password)
    9. Dim myBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(myAuth)
    10. Dim my64BytesHeader As String = Convert.ToBase64String(myBytes)
    11.  
    12. 'creates the request
    13. tempHttpWebRequest = CType(WebRequest.Create(queryString), HttpWebRequest)
    14.  
    15. tempHttpWebRequest.Method = "GET"
    16. tempHttpWebRequest.Headers.Add("Authorization", "basic " & my64BytesHeader)
    17.  
    18. Dim myStream As IO.Stream = tempHttpWebRequest.GetRequestStream
    19. 'Sends the data.
    20. myStream.Write(postInformationByteArray, 0, postInformationByteArray.Length)
    21. myStream.Close()
    22.  
    23. tempHttpWebResponse = CType(tempHttpWebRequest.GetResponse, HttpWebResponse)
    24.  
    25.       'saves the response in a buffer
    26. Dim tempStream As IO.Stream = tempHttpWebResponse.GetResponseStream()
    27. Dim inBuf(100000) As Byte
    28. Dim bytesToRead As Integer = CInt(inBuf.Length)
    29. Dim bytesRead As Integer = 0
    30.  
    31. While bytesToRead > 0
    32.   Dim n As Integer = tempStream.Read(inBuf, bytesRead, bytesToRead)
    33.   If n = 0 Then
    34.     Exit While
    35.   End If
    36.   bytesRead += n
    37.   bytesToRead -= n
    38. End While
    39.  
    40. 'writes the buffer into file
    41. Dim tempFileStream As New IO.FileStream("httpWebRequest.txt", IO.FileMode.CreateNew, IO.FileAccess.Write)
    42. tempFileStream.Write(inBuf, 0, bytesRead)
    43. tempStream.Close()
    44. tempFileStream.Close()
    45. 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
  •  



Click Here to Expand Forum to Full Width