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:
My code attempt that returns the header information, but the SearchResult is NULL:
Imports Newtonsoft.Json
(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.
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\" }}"
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.