Results 1 to 3 of 3

Thread: [RESOLVED] CURL in VB.net (API)

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2013
    Posts
    178

    Resolved [RESOLVED] CURL in VB.net (API)

    Does anyone have a working sample of CURL to VB.net? I have exhausted every example I can find and all of them return NULL search results. I can run the CURL from a command prompt and it returns everything expected. I just can't find a way to get this to work from VB:

    This CURL works perfectly from a command prompt:

    Code:
    curl -X POST "https://api.mouser.com/api/v1/search/keyword?apiKey=YOURSECRETKEY" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"SearchByKeywordRequest\": {    \"keyword\": \"LMK105BJ224KV-F\",    \"records\": 0,    \"startingRecord\": 0,    \"searchOptions\": \"string\",    \"searchWithYourSignUpLanguage\": \"string\"  }}"
    My code attempt that returns the header information, but the SearchResult is NULL:

    Imports Newtonsoft.Json

    Code:
            ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
            Dim Mfr As String = "string"
            'Dim dictData As New Dictionary(Of String, String)
            'dictData.Add("keyword", Mfr)
            'dictData.Add("records", 0)
            'dictData.Add("startingrecord", 0)
            'Dim DictStr As String = JsonConvert.SerializeObject(dictData, Formatting.None)
            Dim senddata As String = "{  \""SearchByKeywordRequest\"": {    \""keyword\"": \""LMK105BJ224KV-F\"",    \""records\"": 0,    \""startingRecord\"": 0,    \""searchOptions\"": \""string\"",    \""searchWithYourSignUpLanguage\"": \""string\""  }}"
            Dim web As New Net.WebClient
            web.Headers.Add(Net.HttpRequestHeader.Accept, "application/json")
            web.Headers.Add(Net.HttpRequestHeader.ContentType, "application/json")
            Dim response = web.UploadString("https://api.mouser.com/api/v1/search/keyword?apiKey=YOURSECRETKEY", "POST", senddata)
    
            Dim jsonResulttodict = JsonConvert.DeserializeObject(Of Dictionary(Of String, Object))(response)

    (I am reposting the code here without a wrapper because it keeps removing my '\' escapes when I wrap it in VB.net highlight)



    This is just one example of about half a dozen I have tried, all with the same result. I believe it must have something to do with formatting the 'senddata' string correctly but I'm not sure.
    Last edited by Fedaykin; Oct 28th, 2020 at 04:52 PM.

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