Results 1 to 2 of 2

Thread: Need to convert a CURL command with Data to VB.net

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2022
    Posts
    6

    Need to convert a CURL command with Data to VB.net

    Hi, I need to convert a cURL string in VB.net but I'm not able. I suppose I create a wrong data string.

    This is the cURL working string:

    curl -XPOST 'https://app.esendex.it/API/v1.0/REST/sms'

    -H 'Content-Type: application/json'
    -H 'user_key: MyKey' -H 'Session_key: MySessionKey'
    -d '{"message_type": "N", "message": "Hello!", "recipient": ["1234567890"], "sender": "Bill", "returnCredits": true}'

    ...and this is my code:

    Private Sub SendMessage()
    Dim webRequest As WebRequest = WebRequest.Create("https://app.esendex.it/API/v1.0/REST/sms")
    Dim myReq As HttpWebRequest

    Dim myData As String = "{'message_type': 'N', 'message': 'Hello!', 'recipient': '1234567890', 'sender': 'Bill, 'returnCredits': true}"
    Dim web As New Net.WebClient
    web.Headers.Add(Net.HttpRequestHeader.Accept, "application/json")
    web.Headers.Add(Net.HttpRequestHeader.ContentType, "application/json")
    web.Headers.Add("user_key", MyKey)
    web.Headers.Add("Session_key", MySessionKey)
    Dim response = web.UploadString("https://app.esendex.it/API/v1.0/REST/sms", "POST", myData)
    Dim jsonResulttodict = JsonConvert.DeserializeObject(Of Dictionary(Of String, Object))(response)

    myReq.GetRequestStream.Write(System.Text.Encoding.UTF8.GetBytes(myData), 0, System.Text.Encoding.UTF8.GetBytes(myData).Count)

    End Sub
    Response give me this error:

    The remote server returned an error: (400) Bad Request.

    Can someone help me ?

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    Re: Need to convert a CURL command with Data to VB.net

    Please use code tags to enclose code. Use the "#" button while writing you message.

Tags for this Thread

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