How to change key type from text to file like in Postman but in Insomia? - post

Aloha,
Question: How to change the key type from text to file like in Postman but in Insomnia?
Reference From Postman
Problem: Cannot test POST on localhost:8080/predict/upload.
Reason: Testing back-end to see if file type is jpeg.
Expectation: Insomnia to produce same results from Postman.
Tried: Used Form urlEncoded and Binary File to POST http://localhost:8080/predict/upload but received 400 bad request.
Reference From Insomnia
Thank you!

Related

Getting SignatureDoesNotMatch error from SQS SendMessage

I am constructing my own REST calls for SQS SendMessage Action.
All the parameters for SendMessage are in request body. (QueueUrl, Action and MessageBody).
I have created my own signature calculation code(mostly copied from AWS SDK Java).
Now, when my MessageBody="HelloWorld" , it works fine.
That means my signature calculation and credentials are correct.
But, when I insert a space , MessageBody="Hello World", I am getting a 403 SignatureDoesNotMatch error from SQS.
I also tried "Hello%20World" as MessageBody , but that also returns a 403 error.
Also tried "Hello+World". But got same error.
I found that aws sdk converts spaces to '+' before calculating the hash of payload.
I tried MessageBody="Hello.World" and that also worked perfectly.
Is there any issue with spaces in Message Body ?
I am sending Host and x-amz-date as the only headers in my request.
The error response from SQS suggests that the hash of the payload is the only thing different in the actual and expected canonical request.

Postman gives right response,but restassured returns empty for same request?

As you can see that postman returns expected result
but res.asString() gives [] in the blow code,can you tell me why?
def "simple test"(){
String url="http://xxx.xxx.xxx/assessment/api/Test.html"
when:""
io.restassured.response.Response res=RestAssured.given().header("Content-Type", "application/x-www-form-urlencoded").formParam("Action", "getDiagnosisList").formParam("Data", "[{\"subject\":\"冠心病\",\"option\":\"是\"}]").post(url)
then:""
res.prettyPrint()=="[\"身体健康状态不良\",\"医疗处置\"]"
}
It turns out that Chinese characters can't be encoded correctedly by default,after adding blow code,everything worked as expected:
RestAssured.given().config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().defaultContentCharset("UTF-8")))
Maybe the request did via postman has not been cached, and on the other hand the same request via restassured is using some kind of cache. Recently I was having a similar issue because of it was hitting the varnish server. I'd recommend you to take a look at the response headers from both postman and restassured.

Amazon MWS Products API returns 401 error "Access denied"

I'm hopelessly stuck on trying to call Amazon MWS Products API. Particularly I'm trying to request this function
It requires building a pretty complicated request with a signature:
POST /Products/2011-10-01 HTTP/1.1
Content-Type: x-www-form-urlencoded
Host: mws.amazonservices.com
User-Agent: <Your User Agent Header>
AWSAccessKeyId=AKIAEXAMPLEFWR4TJ7ZQ
&Action=ListMatchingProducts
&MWSAuthToken=amzn.mws.4ea38b7b-f563-7709-4bae-87aeaEXAMPLE
&MarketplaceId=ATVPDKIKX0DER
&Query=0439708184
&SellerId=A1IMEXAMPLEWRC
&SignatureMethod=HmacSHA256
&SignatureVersion=2
&Timestamp=2012-12-12T22%3A23%3A50Z
&Version=2011-10-01
&Signature=V%2BEXAMPLERT%2Baj%2Fxwqo7y3PIifMFHeqFlNYW0EXAMPLEA%3D
I build this query with the help of this little library:
So my final url string looks like this:
https://mws.amazonservices.com/Products/2011-10-01?AWSAccessKeyId=<MY_ACCESS_KEY>&Action=ListMatchingProducts&MarketplaceId=A1PA6795UKMFR9&Query=0439708184&SellerId=<SELLER_ID>&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-04-19T16%3A50%3A13Z&Version=2011-10-01&Signature=mZt3OhM14gwLdsQ%2Bhxz5UFMzr7m2U36DvZ7RG3dcsTI%3D
And it seems that the url string is built correctly. I think so because if a parameter is missing or incorrect the API returns 400 error with explanation that this parameter is invalid. The same applies for the signature. If signature is incorrect the API returns error which clearly states that the signature is invalid. So, again, I think that the url must be ok. However the API returns 401 error and a html page which looks like this:
<?xml version="1.0"?>
<ErrorResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<Error>
<Type>Sender</Type>
<Code>AccessDenied</Code>
<Message>Access denied</Message>
</Error>
<RequestID>7b12e3c8-7b1a-4b6e-b7ba-15ec8c4e0968</RequestID>
</ErrorResponse>
Access denied. And I have no idea why. I've spent several hours already trying to figure out what's wrong. Can anyone help me?
The reason for the problem was that I was calling American url https://mws.amazonservices.com instead of European one https://mws-eu.amazonservices.com. It would be really nice if Amazon response gave more context about the error than simply Access denied

How to upload a file in Telegram Bott api using Http client?

I have tried to send files using multipart form data, but all I get is the following error:
{"description":"Error: Bad Request: chat_id is empty","error_code":400,"ok":false}
Here is my code snippet. Can anyone help me out where I am committing an error?
public HttpResponse<jsonnode> sendDocument(Integer chat_id,File f1) throws UnirestException {
return Unirest.post(endpoint + token + "/sendDocument")
header("accept", "application/json")
.field("chat_id", chat_id)
.field("document", f1)
.asJson();
}
well, it said chat_id is empty. that's an obvious error!
but for your question, there is only two ways to sendDocument to telegram.
that file is already is in their servers, so you should just pass the file_id in "document" field
you want to upload a file from your device and as they said
Must be posted using multipart/form-data in the usual way that files are uploaded via the browser
if you are doing the upload section correct, then just make sure chat_id is not empty.

Google docs API: can't download a file, downloading documents works

I'm trying out http requests to download a pdf file from google docs using google document list API and OAuth 1.0. I'm not using any external api for oauth or google docs.
Following the documentation, I obtained download URL for the pdf which works fine when placed in a browser.
According to documentation I should send a request that looks like this:
GET https://doc-04-20-docs.googleusercontent.com/docs/secure/m7an0emtau/WJm12345/YzI2Y2ExYWVm?h=16655626&e=download&gd=true
However, the download URL has something funny going on with the paremeters, it looks like this:
https://doc-00-00-docs.googleusercontent.com/docs/securesc/5ud8e...tMzQ?h=15287211447292764666&amp\;e=download&amp\;gd=true
(in the url '&amp\;' is actually without '\' but I put it here in the post to avoid escaping it as '&').
So what is the case here; do I have 3 parameters h,e,gd or do I have one parameter h with value 15287211447292764666&ae=download&gd=true, or maybe I have the following 3 param-value pairs: h = 15287211447292764666, amp;e = download, amp;gd = true (which I think is the case and it seems like a bug)?
In order to form a proper http request I need to know exectly what are the parameters names and values, however the download URL I have is confusing. Moreover, if the params names are h,amp;e and amp;gd, is the request containing those params valid for obtaining file content (if not it seems like a bug).
I didn't have problems downloading and uploading documents (msword docs) and my scope for downloading a file is correct.
I experimented with different requests a lot. When I treat the 3 parameters (h,e,gd) separetaly I get Unauthorized 401. If I assume that I have only one parameter - h with value 15287211447292764666&ae=download&gd=true I get 500 Internal Server Error (google api states: 'An unexpected error has occurred in the API.','If the problem persists, please post in the forum.').
If I don't put any paremeters at all or I put 3 parameters -h,amp;e,amp;gd, I get 302 Found. I tried following the redirections sending more requests but I still couldn't get the actual pdf content. I also experimented in OAuth Playground and it seems it's not working as it's supposed to neither. Sending get request in OAuth with the download URL responds with 302 Found instead of responding with the PDF content.
What is going on here? How can I obtain the pdf content in a response? Please help.
I have experimented same issue with oAuth2 (error 401).
Solved by inserting the oAuth2 token in request header and not in URL.
I have replaced &access_token=<token> in the URL by setRequestHeader("Authorization", "Bearer <token>" )

Resources