I need to code this Curl/json command on VB.net. I am not sure how to use HttpWebRequest. Please HELP!!!
curl -X GET --header "Accept: /" --header "X-Auth-Token: eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0NTc3NTQ1" "http://staging-exact-integration.posios.com/PosServer/rest/core/company"
HttpClient is what you're after.
To add headers, you simply create a custom HttpRequestMessage:
Dim client As New HttpClient()
Dim request As New HttpRequestMessage() With
{
.RequestUri = New Uri("http://staging-exact-integration.posios.com/PosServer/rest/core/company"),
.Method = HttpMethod.Get,
}
request.Headers.Add("X-Auth-Token", "eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0NTc3NTQ1")
Dim result = client.SendAsync(request).Result
Related
I use a curl to get the status of a Jira issue :
result = sh(returnStdout: true, script: """curl -D- -k -u $JIRA_LOGIN:$JIRA_PWD -X GET -H "Content-Type: application/json" $url""")
This returns a String like :
{"expand":"renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations","id":"*****","self":"*****","key":"*****","fields":{"status":{"self":"*****","description":"Issues in development","iconUrl":"****","name":"DEVELOPMENT","id":"10400","statusCategory":{"self":"****","id":4,"key":"indeterminate","colorName":"yellow","name":"In Progress"}}}}
How I can extract the data "DEVELOPMENT" in this string ? I try to parse it in JSON but it's not working :
status_json = new JsonSlurper().parse(result)
with the error "java.io.NotSerializableException: groovy.json.JsonSlurper"
You can check out the JsonSlurper's documentation:
Jira holds all issue fields under the "fields" key in JSON. So, after you get the JSON, you just need to go to the fields.status.name in order to get "DEVELOPMENT" text.
Here's a simple approach:
def jsonSlurper = new JsonSlurper()
def issueObj = jsonSlurper.parseText('...') // Your Jira response will be here
issueObj.fields.status.name // It will give you the status' name.
I am trying to create my first REST app and I am using Swagger to document and test it. My controller receives POST in JSON:
"body": {
"search_query" : "text",
"page" : 1
}
I thought I can annotate controller like this:
#ApiImplicitParams({
#ApiImplicitParam(name="search_query",value="Text to search for",required = false,dataType = "String",paramType = "body"),
#ApiImplicitParam(name="page",value="Page number",required = true,dataType = "int",paramType = "body")
})
But generated curl looks like this:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '1' 'http://localhost:9000/api/search'
And this is not what I am looking for.. , then I found out I can not have 2 body parameters. But how do I annotate my controller then , if I do not want to create class for this data and annotate it with model?
I use this curl command:
curl -X POST -H "Content-Type: application/json" http://localhost:8081/creditcard -d '{"credit-card":"1234-5678-9101-1121"}'
In my js file, I have this code block to get the credit-card's value:
request.on('data', function(data) {
var cc = 'credit-card';
var a = JSON.parse(data.toString());
console.log(a[cc]);
}
For this I get:
undefined:1
'{credit-card:1234-5678-9101-1121}'
^
SyntaxError: Unexpected token '
at Object.parse (native)
at IncomingMessage.<anonymous> (<path>\ccserver.js:32:34)
at IncomingMessage.emit (events.js:107:17)
at IncomingMessage.Readable.read (_stream_readable.js:373:10)
at flow (_stream_readable.js:750:26)
at resume_ (_stream_readable.js:730:3)
at _stream_readable.js:717:7
at process._tickCallback (node.js:355:11)
So I tried to use JSON.stringify as followed:
request.on('data', function(data) {
var cc = 'credit-card';
var a = JSON.parse(JSON.stringify(data.toString()));
console.log(a[cc]);
}
But this is what I get:
undefined
undefined
However, when I try to parse a hard-coded json string, it goes ok:
var jsonString = '{"credit-card":"1234-5678-9101-1121"}';
var a = JSON.parse(jsonString);
console.log(a[cc]);
Result:
1234-5678-9101-1121
What is the correct way to do get the data out of this json?
Please advise
Thanks
Try reading from absolute path
curl -X POST
-H 'Content-Type:application/json'
-H 'Accept: application/json'
--data-binary #/full/path/to/test.json
http://server:port/xyz/abc/blah -v -s
Well, you already have String so all you need to convert it to javascript variable and get using .notation. Suggest to use firebug to see what is in variable.
obj = JSON.parse(json);
obj.cc or obj.cc[0]
should give you what you want.
I have inherited a controller.
When a post request is made, with a well structured JSON document everything is fine.
When the JSON contains a space in a feld, 404 is returned.
However, when the same request is made from mozilla restclient extension everything works.
The CURL request specifically is:
curl --include \
--request POST \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data-binary "{
"planCode" : "My Test App-standard"
}" \
"https://localhost/signupApi/v2/signup"
URLMapping:
"/signupApi/v2/$action"{
parseRequest = true // parse json, and assign to params
controller = "signupApiSignup"
}
So, why would a space in curl cause problems in the request body that grails receives?
Thanks
You are not quoting your strings there properly in your shell. Use ' for your parameters, if you plan to use "sensitive" chars like " there. Or use \" inside. Also curl can read a filename if you prefix it with # instead of the actual data.
Yet in this case maybe quoting with ' is easiest. E.g.:
...
--data-binary '{
"planCode" : "My Test App-standard"
}'
...
I have BOX account and in API document
curl https://upload.box.com/api/2.0/files/content \
-H "Authorization: Bearer ACCESS_TOKEN" \
-F filename=#FILE_NAME \
-F parent_id=PARENT_FOLDER_ID
I am stuck with this filename and parent_id how to pass the filename and parent_id
i have tried lots of way, but nothing is working for me.
Following is the code:
httpWReq.Method = "POST";
httpWReq.Headers.Add("Authorization", "Bearer ");
httpWReq.ContentType = "multipart/form-data";
//{\"parent_id\":\""+parentID +"\"}
//byte[] file = File.ReadAllBytes(postData);
httpWReq.ContentLength = data.Length;
using (Stream reqStream = httpWReq.GetRequestStream())
{
reqStream.Write(data, 0, data.Length);
//reqStream.Close();
}
using (HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse())
{
//Console.WriteLine("HTTP/{0} {1} {2}", response.ProtocolVersion, (int)response.StatusCode, response.StatusDescription);
response.Close();
}
Need Help
Thanks in Advance
Vaibhav,
Please see example of how official Box C# SDK is doing upload:
https://github.com/box/box-windows-sdk-v2/blob/master/Box.V2/Managers/BoxFilesManager.cs
Is there any reason why you don't want to use Box Windows SDK?