I am calling a web service from Classic ASP/VBScript. The call expects 3 parameters, 1 which is form data and 2 which are optional file data. Currently not sending the file data.
The form data is multiple fields, wrapped up in json.
So I'm setting the content-type on the ServerXMLHTTP object to be multipart/form-data, and I'm creating the json segment as such and sending it as the data
Content-Type: application/json; charset=utf-8
{
"Token": "...",
"FirstName": "First Name",
I keep getting Request must be Content-type: multipart/form-data.
I've tried adding a boundary and same thing.
I know I can do this in C# using MultipartFormDataContent, but it has to be Classic unfortunately.
What's the correct way to send? Thanks!
Related
I am trying to query an API where I have to pass username and password in the body. I have researched multiple methods but have not found any method which seems reasonable.
My query looks something like this:
URL:
localhost:8080/v1/project
HEADERS:
Content-Type: application/json
BODY:
{
"email": "test#test.com",
"password": "123456"
}
In the docs I have found WebActions.Request, which is aparently disabled in most contexts (https://learn.microsoft.com/en-us/powerquery-m/webaction-request).
Web.Contents only allows a body in POST requests (https://learn.microsoft.com/en-us/powerquery-m/web-contents).
I'd rather not write a Python script to do it as it requires a Python installation.
I tried this possible solution, but there was no success, as it would still perform a POST request: https://community.powerbi.com/t5/Power-Query/How-to-send-a-GET-method-with-content-data-with-M/m-p/943033/highlight/true#M32541
What reasonable way is there to achieve my goal to do a GET request with a body containing the credentials?
I have my API Gateway set up with application/json Content-Type mapped to
{
"param1": "$input.params('param1')"
}
and application/pdf mapped to
{
"content": "$input.body"
}
Both of these work on their own when I use postman and specify the Content-Type as one or the other.
But, I want to be able to make a request that can take both pdf binary data along with some parameters from JSON using one call and use both in lambda.
I've tried adding both of these in a content-type and setting the template as
{
"content": "$input.body",
"param1": "$input.params('param1')"
}
But this returns back an error when I call it with the params and the pdf:
"message": "Could not parse request body into json: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n
The "param1" is a query string parameter I have added.
Have installed reviewboard 2.5.7.
If I create review request from commit using UI it works fine.
If I using API it creates empty request and looks like ignore the JSON body at all.
POST http://myhost/api/review-requests/
Authorization: token bla-bla
Accept: application/json
{
"changenum": null,
"commit_id": "e235168b0f0528d006fa2872bf582896ae121909",
"create_from_commit_id": true,
"force_text_type": null,
"repository": "myrepo",
"submit_as": null
}
Does API really supports request from commit?
Got it: that api isn't supports JSON request.
It should be application/x-www-form-urlencoded with form parameters.
I am trying to send mails with attachment by using Amazon SES
HttpRequest httpReq = new HttpRequest();
httpReq.setMethod('POST');
httpReq.setEndpoint('https://email.us-east-1.amazonaws.com');
Blob bsig = Crypto.generateMac('HmacSHA256', Blob.valueOf(awsFormattedNow), Blob.valueOf(secret));
httpReq.setHeader('X-Amzn-Authorization','AWS3-HTTPS AWSAccessKeyId='+key+', Algorithm=HmacSHA256, Signature='+EncodingUtil.base64Encode(bsig));
httpReq.setHeader('Date',awsFormattedNow);
httpReq.setHeader('From','sample#gmail.com');
httpReq.setHeader('To','sample#gmail.com');
httpReq.setHeader('Subject','Hello');
httpReq.setHeader('Accept-Language','en-US');
httpReq.setHeader('Content-Language','en-US');
httpReq.setHeader('Content-Type','multipart/mixed;boundary=\"_003_97DCB304C5294779BEBCFC8357FCC4D2\"');
httpReq.setHeader('MIME-Version','1.0');
// httpReq.setHeader('Action','SendRawEmail');
String email = 'Action=SendRawEmail';
email += '--_003_97DCB304C5294779BEBCFC8357FCC4D2 \n Content-Type: text/plain; charset="us-ascii" \n Content-Transfer-Encoding: quoted-printable \n';
email +='Hi Andrew. Here are the customer service names and telephone numbers I promised you.';
httpReq.setBody(email);
System.debug(httpReq.getBody());
Http http = new Http();
HttpResponse response = http.send(httpReq);
I am getting error like
<AccessDeniedException>
<Message>Unable to determine service/operation name to be authorized</Message>
</AccessDeniedException>
Kindly please help me where i am doing wrong .Thanks in advance
Take another look at the documentation. There are several issues with your code.
SES expects an HTTP POST with all of the parameters strung together consistent with application/x-www-form-urlencoded POST requests.
Your HTTP request needs to be Content-type: application/x-www-form-urlencoded, not multipart/mixed... -- that's part of the raw message you're trying to send.
You are mixing up things that should be in the body, and setting HTTP request headers, instead. For example, these are also incorrect:
httpReq.setHeader('From','sample#gmail.com');
httpReq.setHeader('To','sample#gmail.com');
httpReq.setHeader('Subject','Hello');
These should go in the request body, not in the HTTP request headers. Also, the values are urlencoded. From the example code:
Action=SendEmail
&Source=user%40example.com
&Destination.ToAddresses.member.1=allan%40example.com
The line breaks were added for clarity.
Your interests might be best served by trying to successfully send a simple e-mail, first, and then later attempting to modify your code to support attachments, because you have numerous errors that will need to be corrected before this code will work properly.
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/query-interface-requests.html
http://docs.aws.amazon.com/ses/latest/APIReference/API_SendRawEmail.html
I'm currently trying to get a POST request using multipart/form-data running to the Django REST framework. I've successfully run through some test requests via the interactive API screens, which work fine. I've then tried to convert these over to using a non-Session based auth strategy, and I've consistently got errors. The requests I've sent are of the form:
POST /api/logs/ HTTP/1.1
Host: host:8080
Connection: keep-alive
Content-Length: 258
Accept: application/json
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryTOhRsMbL8ak9EMQB
Authorization: Token -token-
------WebKitFormBoundaryx6ThtBDZxZNUCkKl
Content-Disposition: form-data; name="SubmittedAt"
2014-01-23T10:39:00
------WebKitFormBoundaryx6ThtBDZxZNUCkKl
Content-Disposition: form-data; name="Device"
CheeseDevice
------WebKitFormBoundaryx6ThtBDZxZNUCkKl--
Sadly, the result has been (for all the requests I've run):
{"Device": ["This field is required."], "SubmittedAt": ["This field is required."], "LogFile": ["This field is required."]}
Interestingly, I've been able to send chunks of JSON through to the endpoint, and they're accepted as expected, eg:
POST /api/logs/ HTTP/1.1
Content-Type: application/json
Host: host:8080
Connection: keep-alive
Content-Length: 35
Accept: application/json
Authorization: Token -token-
{
"Device": "CheeseDevice"
}
Returns:
{"SubmittedAt": ["This field is required."], "LogFile": ["This field is required."]}
As expected - it actually accepts the Device argument and only raises errors on the missing items. I'd switch to using JSON, but sadly cannot upload files with it...
Thanks in advance for any help!
Edit:
Further investigation (ie: writing a view method that returns the request data shows that request.DATA isn't getting populated, for some reason. Method I'm using to debug follows:
def test_create(self, request, pk=None):
return Response(request.DATA)
Edit 2:
Even further investigation (and dropping code chunks into the framework for debugging) indicates that the requests are getting caught up in _perform_form_overloading and never hitting the MultiPartParser. Not sure why this is occurring but I'll try and trace it further.
After delving down every level I could find...
Looks like the problem stems from the line endings - ie: the libs and request senders I've been using send the content through with "\n" (LF) endings, while the HTTP spec requires "\r\n" endings (CR,LF)
This hinges on the following code in the Django core, within http/multipartparser.py - in parse_boundary_stream:
header_end = chunk.find(b'\r\n\r\n')
For dev purposes (and because it's going to be way easier to patch at the Django end than in the clients...) I've switched the above line to:
header_end = chunk.replace("\r\n","\n").find(b'\n\n')
This updated code follows the recommendations in Section 19.3 of the HTTP/1.1 spec regarding Tolerant Applications and accepting LF instead of just CRLF - I'll try and get around to seeing if this is suitable for inclusion in the Django core.
Edit:
For reference, the patch is up on GitHub: https://github.com/tr00st/django/commit/9cf6075c113dd27e3743626ab0e18c6616488bd9
This could be due to malformed multipart post data.
Also possible that you don't have MultiPartParser installed, but I don't think that'll be it as you'd normally expect to see a 415 Unsupported Media Type response in that case.