I use python requests to send multipart POST:
files = {"file1": open("C:\\Users\\Path\\to\\file1.xml", 'r'),
"file2": open("C:\\Users\\Path\\to\\file2.crt", 'r'),
"file3": open("C:\\Users\\Path\\to\\file3.pem", 'rb'),
"file4": open("C:\\Users\\Path\\to\\file4.elf", 'rb')}
url = "http://some_url.com"
r = requests.post(url, data={"targetName": "Qwerty"}, files=files)
I want to rewrite it using cURL. There's a lot of information about how to do this, but none of found approaches seem to work. For now I have something like:
curl -F 'targetName=Qwerty' -F 'file1=#\"C:\\Users\\Path\\to\\file1.xml\"' -F 'file2=#\"C:\\Users\\Path\\to\\file2.crt\"' -F 'file3=#\"C:\\Users\\Path\\to\\file3.pem\"' -F 'file4=#\"C:\\Users\\Path\\to\\file4.elf\"' http://some_url.com
but this returns
400 Bad Request
<html><head><title>Error</title></head><body>Required MultipartFile parameter 'file1' is not present</body></html>* Closing connection 0
What is wrong with my request? Do I need to specify headers?
Related
Following the indications provided by this gem , testing in the Rails console the RestClient
RestClient.post "https://upload.twitter.com/1.1/media/upload.json?media_category=tweet_image", :myfile => File.new("/Users/main/Desktop/ss2022-11-03_11.39.11.png", 'rb')
one can assert that the file exists by changing its path. Once verified, the response returns
400 Bad Request. So the request is malformed. Alas, I do not grasp what the second element of the File.new represents
The version 1.1 API documentation provides a suggestion console test
twurl -X POST -H upload.twitter.com "/1.1/media/upload.json?media_category=TWEET_IMAGE&additional_owners=3805104374" -f adsapi-heirarchy.png -F media
the response is the same whether the additional_owners is included or not (logical, it is optional).
What is missing in this sequence?
Thr translation of the twurl syntax to curl syntax would be:
curl "https://upload.twitter.com/1.1/media/upload.json?media_category=tweet_image&additional_owners=3805104374" --data-urlencode #/Users/main/Desktop/adsapi-heirarchy.png --data-urlencode 'media'
I have defined a file with name - play.rego
package play
default hello = false
hello {
m := input.message
m == "world"
}
I also have file called -input.json
{ "message": "world"}
I now want to use the policy to evaluate on input data using opa server -
opa run --server
I also then registered the policy using below command -
curl -X PUT http://localhost:8181/v1/policies/play --data-binary #play.rego
and then I run below command for evaluating policy on the query -
curl -X POST http://localhost:8181/v1/policies/v1/data/play --data-binary '{"message": "world"}'
But the server always responds with nothing.
I need help fixing the problem?
The URL of the second request is wrong (should not contain v1/policies), and the v1 API requires you to wrap the input document inside an input attribute. Try:
curl -X POST http://localhost:8181/v1/data/play --data-binary '{"input":{"message": "world"}}'
i'm trying to send a parse.com push notification from ruby 1.8.7.
i got a test working with curl. but with ruby's net::http i'm getting Timeout::Error: Resource temporarily unavailable
how can i debug this? i don't know how to see why the parse server is responding differently or otherwise see what's happening. i tried sending the request to my own server and the headers looked ok to me.
i simplified what i'm doing to this:
http = Net::HTTP.new('api.parse.com', 443)
response = http.post("/1/push", "{\"where\":{},\"data\":{\"alert\":\"Elliot net http json test 1\"}}", {"X-Parse-Application-Id"=>"xxxxx", "Content-Type"=>"application/json", "X-Parse-REST-API-Key"=>"xxxxx"})
the json there is hard to read, it's from:
api_req = {:where => {}, :data => {:alert => "Elliot net http json test 1"}}.to_json
puts api_req
# {"where":{},"data":{"alert":"Elliot net http json test 1"}}
i also tried several other ways of sending a request with net::http. same result.
the curl request that worked was:
curl -X POST \
-H "X-Parse-Application-Id: xxxxxx" \
-H "X-Parse-REST-API-Key: xxxxx" \
-H "Content-Type: application/json" \
-d '{
"where": {},
"data": {
"alert": "Elliot curl test #4"
}
}' \
https://api.parse.com/1/push
i'm not using parse-ruby-client because i ran into problems with dependencies assuming a newer version of ruby. all i need to do is send some simple push notifications, and it seems like this should work without too much trouble.
can anyone help me get this working or tell me how to get some useful info about what's happening to debug?
As per the REST API Developers guide,
All API access is over HTTPS, and accessed via the https://api.parse.com domain.
So all you need to do is to add http.use_ssl = true.
I'm working on a db migration where I need to upload images in the old db to Filepicker using cURL within the Rails console. I've got a command that works, and all I need from here is to grab the Filepicker URL from the response. However, setting the response as below just returns true.
So this will upload a file to Filepicker as desired:
res = system("curl -X POST -F fileUpload=#oldimages/oldimage#{id}.jpg https://www.filepicker.io/api/store/S3\?key\=OURAPIKEY")
Giving this output:
{"url": "https://www.filepicker.io/api/file/THEURL", "size": 207610, "type": "image/jpeg", "filename": "oldimage1.jpg"} => true
The problem is I can't assign the URL - the res variable only stores true.
So, in a nutshell, how to I get access to the rest of this data to assign it to an instance in the new db?
If you need run curl you can do this
body=`curl -X POST -F fileUpload=#oldimages/oldimage#{id}.jpg https://www.filepicker.io/api/store/S3\?key\=OURAPIKEY`
or
body = %x(curl -X POST -F fileUpload=#oldimages/oldimage#{id}.jpg https://www.filepicker.io/api/store/S3\?key\=OURAPIKEY)
or
IO.popen("curl -X POST -F fileUpload=#oldimages/oldimage#{id}.jpg https://www.filepicker.io/api/store/S3\?key\=OURAPIKEY").read
But If I were you, I would try to use net:http or another ruby http client as typhoeus or restclient
If i issue a POST request using curl command to github api to add "Resolved" label; things are good.
curl -i -H "Authorization: token xxxxxxxxxxxx" -X POST 'https://git.corp.yahoo.com/api/v3/repos/owner/repo/issues/1/labels' -d '["Resolved"]'}
But when i try to do the same using Curl easy in my Ruby script
set gh_api = https://git.corp.yahoo.com/api/v3/repos/owner/repo/issues/1/labels
curl = Curl::Easy.http_post(settings.gh_api,'["Resolved"]')
do |c|
c.headers = ["Authorization: token xxxxxxxx"]
end
The JSON reponse I get is
"{\"message\":\"Not Found\"}"
What am i doing wrong in my ruby script?
It's not at all clear what question you are asking because there is no question.
What's returned is a JSON response. Why don't you parse it with the JSON class and see what it returns:
require 'json'
puts JSON["{\"message\":\"Not Found\"}"]
=> {"message"=>"Not Found"}
I'm guessing that the problem is in the path of the URL if the response is "Not Found".
My URL was wrong. I ended the URL with a '/'.