I'm programming in Java.
I developed a test web service in which I pass a random json and the service returns me hello
Here the web service code:
#Path("test")
#GET
#Consumes(MediaType.APPLICATION_JSON)
public String test(#HeaderParam("token") String token, #QueryParam("array")String array)
{
return "hello";
}
I call the service with curl
curl -v -H 'token:aaaa' 'http://140.145.1.2/clayapi/restservices/test?array=[{"name":"george","lastname":"ronney"}]';
message of error:
curl: (3) [globbing] illegal character in range specification at pos 60
I tried to add -g but it doesn't work .. how should I do?
Use -G along with --data-urlencode:
curl -v -G 'http://example.org' \
-H 'header:value' \
--data-urlencode 'array=[{"name":"george","lastname":"ronney"}]'
From the documentation:
-G, --get
When used, this option will make all data specified with -d, --data, --data-binary or --data-urlencode to be used in an HTTP GET request instead of the POST request that otherwise would be used. The data will be appended to the URL with a ? separator. [...]
--data-urlencode <data>
(HTTP) This posts data, similar to the other -d, --data options with the exception that this performs URL-encoding. [...]
Related
I found this example of a API request. Unfortunately I didn't find any other example how to upload an image to the API.
As I'm not familiar with Python I'm trying to understand how to do the same in a cURL command.
import requests
auth_headers = {
'app_id': 'your_app_id',
'app_key': 'your_app_key'
}
url = 'https://XXXXXXX'
files = {
'source': open('media/test.jpg')
}
data = {
'timeout': 60
}
response = requests.post(url, files=files, data=data, headers=auth_headers)
I tried to convert it by trying out a cURL to python converter, but I don't know how to build it with the files.
In the end I want to do the request in JAVA, but I think if I would know the request in cURL I can figure it out.
Hope anyone can help me with that.
This will do it:
#!/bin/bash
args=(
-H 'app_id: your_app_id'
-H 'app_key: your_app_key'
-F 'source=#/path/to/file'
-F 'timeout=60'
'http://httpbin.org/post'
)
curl "${args[#]}"
or, as a one-liner:
curl -H 'app_id: your_app_id' -H 'app_key: your_app_key' -F 'source=#/path/to/file' -F 'timeout=60' 'http://httpbin.org/post'
Use -H to specify header fields (repeat for every field) and -F to specify form fields - either as key=value pairs, or filename=#path pairs. When -F is used, POST method is the default, and Content-Type is multipart/form-data (but that too can be overridden).
I'm trying to create Campaign through Apple Search Ads API. So I use
curl -X POST https://api.searchads.apple.com/api/v1/campaigns \
--cert path/XXXX.p12 \
--pass **** \
-H "Authorization: orgId=xxxx" \
-d '{"budgetAmount":{"currency":"USD","amount": 50.0},"name": "weixinCampagin", "adamId":"414478124","adGroups": [{"name": "weixinCampaginAdGroup","startTime":"2017-03-17 00:00:00","defaultCpcBid": {"amount": 1,"currency":"USD"},"storeFronts": ["US"]}]}'
I got the following error messages:
{"data":null,"pagination":null,"error":{"errors":[{"messageCode":"INVALID_ATTRIBUTE_TYPE","message":"This is an invalid request. At least one field format is not readable by the system.","field":"Line#:1 Column#:50"}]}}
I have tried many times through different ways, but still not working. Is there any smart guys can help me?
Thanks in advance!
I think you need to specify that you're sending a json object.
curl \
--cert ./<FILENAME>.p12 \
--pass <PASSWORD> \
-H "Authorization: orgId=<ORG_ID>" \
-H "Content-Type: application/json" \
-d "<CAMPAIGN_DATA_FILE>.json" \
-X POST "https://api.searchads.apple.com/api/v1/campaigns"
Apart from content-type header,
The amount needs to be in string format
'{"budgetAmount":{"currency":"USD","amount": "50.0"},"name": "weixinCampagin", "adamId":"414478124","adGroups": [{"name": "weixinCampaginAdGroup","startTime":"2017-03-17 00:00:00","defaultCpcBid": {"amount": "1","currency":"USD"},"storeFronts": ["US"]}]}'
in https://developer.apple.com/library/content/documentation/General/Conceptual/AppStoreSearchAdsAPIReference/API_Overview.html
the sample also uses string for the amount item
curl -s -S -u user123:321pass https://12.15.13.12:3216 --data
'<?xml version="1.0" encoding="UTF-8"?><data>Hello Man</data>' -H 'Content-Type: text/xml' -k
I need to change this to a Apache Camel route call like :-
private ProducerTemplate producer;// there are setters for this.
producer.requestBodyAndHeaders(endpointUri, requestBody,addHeaders, String.class);
Main question is how do I pass username and password with this requestBodyAndHeaders.I tried passing through headers(header being map, key value pairs)
I would like to send a HTTP GET request that contains a json as a parameter. The server expects the parameter to be encoded with UTF-8.
curl -G -v "http://localhost:8000/job" --data-urlencode "request={"clientId"="13","message"="I want apples"}"
I have used --data-urlencode but it doesn't seam to encode in UTF-8 because the server cannot decode the request.
I have a java client that uses
String charset = StandardCharsets.UTF_8.name();
String requestParameter = request={"clientId":"13","message"="I want apples"}
URLEncoder.encode(requestParameter, charset)
to encode the parameter and then send the HTTP GET request and the server accepts the request and is able to decode correctly.
The correct curl command is:
curl -G -v "http://localhost:8000/job" --data-urlencode 'request={"clientId":"13","messave":"I want apples"}'
I have a rest endpoint as below. pid is UUID which I'm parsing using UUID.fromString(pid);
#GET
#Path("/")
public Response process(#Context HttpServletRequest req,
#QueryParam("p") String pid,
#DefaultValue("3") #QueryParam("a") String active,
#DefaultValue("3") #QueryParam("c") String closed,
#CookieParam("X") String cookie) {
//my stuff
}
This is not setting 'p' and 'X' when I run jetty and curl using
curl localhost:9090/rest/accounts?p=<uuid>&c=4&a=5 -b "X=1212;"
response is -b: command not found
it works when I move cookie part to front
curl -b "X=1212;" localhost:9090/rest/accounts?p=&c=4&a=5
but 'c' and 'a' are always 3 (default).
Is there something wrong with the way I'm using it.
Your shell probably interpreted &, try:
curl -b "X=1212;" "localhost:9090/rest/accounts?p=&c=4&a=5"
If you want to see detail information about request and response use:
curl -v -b "X=1212;" "localhost:9090/rest/accounts?p=&c=4&a=5"