2

I'm looking for a way to convert the following cURL to ASP.Net.

curl -F [email protected] "https://pdftables.com/api?key=ZZZ999&format=xml"

I've used the following function extensively to get virtually any URL/content, but I'm lost on how to include a file located on the hosted web server.

Public Shared Function GetRemoteURL(getURL As String) As String
    Dim objReq As HttpWebRequest
    Dim objRsp As HttpWebResponse = Nothing
    Dim objRdr As StreamReader
    Dim objRes As String = ""
    Try
        objReq = DirectCast(WebRequest.Create(getURL), HttpWebRequest)
        objRsp = DirectCast(objReq.GetResponse(), HttpWebResponse)
        objRdr = New StreamReader(objRsp.GetResponseStream())
        objRes = objRdr.ReadToEnd()
    Catch
        objRes = ""
    Finally
        If Not objRsp Is Nothing Then objRsp.Close()
    End Try
    Return objRes.ToString()
End Function

Any advice/direction would be deeply appreciated.

John

1 Answer 1

2

You'll have to set the request body, something like:

Public Function GetRemoteURL(getURL As String) As String
    Dim objReq As HttpWebRequest
    Dim objRsp As HttpWebResponse = Nothing
    Dim objRdr As StreamReader
    Dim objRes As String = "" 
    Try
        objReq = DirectCast(WebRequest.Create(getURL), HttpWebRequest)

        objReq.Method = "POST"
        Dim postData = "[email protected]"
        Dim encoding As New ASCIIEncoding()
        Dim bytes = encoding.GetBytes(postData) 
        objReq.ContentLength = bytes.Length
        Dim stream = objReq.GetRequestStream()
        stream.Write(bytes, 0, bytes.Length)

        objRsp = DirectCast(objReq.GetResponse(), HttpWebResponse)
        objRdr = New StreamReader(objRsp.GetResponseStream())
        objRes = objRdr.ReadToEnd()
    Catch
        objRes = ""
    Finally
        If Not objRsp Is Nothing Then objRsp.Close()
    End Try
    Return objRes.ToString()
End Function

note: i didn't test this so it might not directly work.

Sign up to request clarification or add additional context in comments.

4 Comments

Let me give it a spint. Thanks for quick reply
I just edited and added objReq.Method="POST", this is probably required.
i think i misunderstood the question a bit. you'll need to read in your pdf file and convert it to bytes, then write that to the stream. more information can be found stackoverflow.com/questions/566462/…
I found a c# example. working with it now. However, I can use your answer for another solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.