how to send payload as multipart/form to request in mule4 - multipartform-data

i transform a payload need to send as as multipart/form to request.
the payload is like below
{
"goods_id": "12345,
"color_id_1": 20,
"image_id_1": vars.png1, //this is binary ,image data
"color_id_2": 11,
"image_id_2": vars.png1, //this is binary ,image data
}
here is sample file which we need to transform, the file is base on postman script.
in postman we can choose image file from notebook. in payload, the image is an object
which is stored in variable .
POST /cooperate/RegistAllImage HTTP/1.1
Content-Type: multipart/form-data; boundary=--------------------------549967118512544277394909
User-Agent: PostmanRuntime/7.29.0
Accept: */*
Cache-Control: no-cache
Postman-Token: ddddd
Host: ddddd
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Cookie: *****
Content-Length: 40980
----------------------------549967118512544277394909
Content-Disposition: form-data; name="goods_id"
Content-Type: application/x-www-form-urlencoded
12345
----------------------------549967118512544277394909
Content-Disposition: form-data; name="color_id_1"
Content-Type: application/x-www-form-urlencoded
20
----------------------------549967118512544277394909
Content-Disposition: form-data; name="image_1"; filename="064df7cefee0421990ccb74a5c1f9ccf.jpg"
Content-Type: application/octet-stream
<064df7cefee0421990ccb74a5c1f9ccf.jpg>
----------------------------549967118512544277394909
Content-Disposition: form-data; name="color_id_2"
Content-Type: application/x-www-form-urlencoded
2
----------------------------549967118512544277394909
Content-Disposition: form-data; name="image_2"; filename="064df7cefee0421990ccb74a5c1f9ccf.jpg"
Content-Type: application/octet-stream
<064df7cefee0421990ccb74a5c1f9ccf.jpg>

You can very well use the Multipart form module or can construct the parts using the script below.
%dw 2.0
import dw::module::Multipart
output multipart/form-data boundary="--------------------------549967118512544277394909"
---
{
parts: {
part1: Multipart::field({
name: "goods_id",
value: payload.goods_id,
mime: "appliation/x-www-form-urlencoded"
}),
part2: Multipart::field({
name: "color_id_1",
value: payload.color_id_1,
mime: "appliation/x-www-form-urlencoded"
})
,
part3: Multipart::field({
name: "image_id_1",
value: payload.image_id_1,
mime: "appliation/octet-stream",
fileName: "064df7cefee0421990ccb74a5c1f9ccf.jpg"
})
,
part4: Multipart::field({
name: "color_id_2",
value: payload.color_id_2,
mime: "appliation/x-www-form-urlencoded"
})
,
part5: Multipart::field({
name: "image_id_2",
value: payload.image_id_2,
mime: "appliation/octet-stream",
fileName: "064df7cefee0421990ccb74a5c1f9ccf.jpg"
})
}
}
Answer to the question in comment:
%dw 2.0
import dw::module::Multipart
output multipart/form-data boundary="--------------------------549967118512544277394909"
---
{
parts: payload mapObject ((value, key, index) -> {
("part" ++ ((index)+1)): Multipart::field({
"name": key as String,
"value": value as String,
"mime": if(key startsWith "image_id_") "application/octet-stream" else "application/x-www-form-urlencoded",
("fileName": "filenmae.png" )if(key startsWith "image_id_")
})
})
}

you can use the Multipart dataweave module that will make it fairly simple.
You will need Multipart::form function to create the form, and pass an array of all the fields, that you have in your payload. I have used pluck for it and then mapped it using Multipart:field function to get an Array of type MultipartPart. Your transform module will look like this
%dw 2.0
import dw::module::Multipart
output multipart/form-data
---
Multipart::form(
payload pluck ((value, key) ->
if(key as String startsWith "image_id_")
Multipart::field(key as String, value, "application/octet-stream")
else Multipart::field( key as String, value as String)
)
)

Related

Alexa Remainder API (REST API) - Invalid bearer token

I am trying to send the Alert/Remainder via POSTMan to my skill.
Option 1: Authentication token API with Scope "alexa:skill_messaging"
POST /auth/o2/token HTTP/1.1
Host: api.amazon.com
Content-Type: application/x-www-form-urlencoded
User-Agent: PostmanRuntime/7.20.1
Accept: */*
Cache-Control: no-cache
Postman-Token: 2ae7afa3-c3f8-493f-b6e3-2db1e44e3a17,a4e45e8e-d0eb-4b3f-a612-e7d1959fdbe6
Host: api.amazon.com
Accept-Encoding: gzip, deflate
Content-Length: 236
Connection: keep-alive
cache-control: no-cache
grant_type=client_credentials&client_id=******************&client_secret=***********17a4f7b348982bdb4&scope=alexa%3Askill_messaging
Screenshote:
option 2: Authentication token API with Scope "alexa::alerts:reminders:skill:readwrite"
POST /auth/o2/token HTTP/1.1
Host: api.amazon.com
Content-Type: application/x-www-form-urlencoded
User-Agent: PostmanRuntime/7.20.1
Accept: */*
Cache-Control: no-cache
Postman-Token: 2ae7afa3-c3f8-493f-b6e3-2db1e44e3a17,c6765f77-6e35-419f-b614-780dae20ad4e
Host: api.amazon.com
Accept-Encoding: gzip, deflate
Content-Length: 236
Connection: keep-alive
cache-control: no-cache
grant_type=client_credentials&client_id=**************************&client_secret=************************&scope=alexa%3A%3Aalerts%3Areminders%3Askill%3Areadwrite
Step 2: Submitting the Alert request using token generated by Scope "alexa:skill_messaging" getting Invalide Bearer token
Let me know if I am missing anything and also where can find different scope for Alexa Authenictaion Token API
Unfortunately,
"That's a limitation of the Reminders API - you need to use the in-session access token to create reminders. You can run GET, UPDATE and DELETE operations out of session as well, so check this out for more information."
Only speaking with the device is possible get in-session access token to create reminders.
Out-session - Get reminders created by the skill (Skill Messaging API):
const IncomingMessageHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'Messaging.MessageReceived'
},
async handle(handlerInput) {
const { requestEnvelope, context } = handlerInput;
console.log(`Message content: ${JSON.stringify(requestEnvelope.request.message)}`);
try {
const client = handlerInput.serviceClientFactory.getReminderManagementServiceClient();
const remindersResponse = await client.getReminders();
console.log(JSON.stringify(remindersResponse));
} catch (error) {
console.log(`error message: ${error.message}`);
console.log(`error stack: ${error.stack}`);
console.log(`error status code: ${error.statusCode}`);
console.log(`error response: ${error.response}`);
}
context.succeed();
}
}
https://developer.amazon.com/docs/smapi/alexa-reminders-api-reference.html#in-session-and-out-of-session-behavior-for-alexa-reminders-api
https://forums.developer.amazon.com/questions/196445/reminders-can-only-be-created-in-session.html#answer-196860
https://developer.amazon.com/pt-BR/docs/alexa/smapi/skill-messaging-api-reference.html

Coinbase Pro API - invalid signature

This is edited from original post:
From the docs:
Signing a Message The CB-ACCESS-SIGN header is generated by creating a
sha256 HMAC using the base64-decoded secret key on the prehash string
timestamp + method + requestPath + body (where + represents string
concatenation) and base64-encode the output. The timestamp value is
the same as the CB-ACCESS-TIMESTAMP header.
Here is information from a key I deleted. This is from Coinbase Pro Sandbox:
publicKey:
06057d5b5e03d0f8587a248330402b21
passPhrase:
gcgs6k6rp0f
secretKey: EFAToD5heo66GIgZlT2TIZzJf8TYlmxyeRxRYDHTBv3lTt9XN6uaNS0RNAy0os/caR47x6EiPDOV3Ik+YzrfEA==
I'm using angular, specifically the node.js crypto-js library:
private generateSignaturePro(timestamp: string, method: string, resourceUrl: string, requestBody: string): string {
var prehash: string = timestamp + method + resourceUrl + requestBody;
var key = (Buffer.from(this.secretKey, 'base64')).toString();
return crypto.enc.Base64.stringify(crypto.HmacSHA256(prehash, key));
}
Server time is Time: 2019-05-20T19:01:38.711Z Epoch: 1558378898.711 (from /time endpoint)
here is my request and the server response:
Request:
Request URL: https://api-public.sandbox.pro.coinbase.com/accounts
Request Method: GET
Status Code: 400
Remote Address: 104.16.161.226:443
Referrer Policy: no-referrer-when-downgrade
Request Headers:
Provisional headers are shown
Accept: application/json, text/plain, */*
CB-ACCESS-KEY: 06057d5b5e03d0f8587a248330402b21
CB-ACCESS-PASSPHRASE: gcgs6k6rp0f
CB-ACCESS-SIGN: 0cc2BnQYdUhLucXSPwMTjpHjJ32G3RXSH44rSsEopvjAtY90uRCMVy6xUrzg/A/aRJBLqx390fcZc7lmJeP++g==
CB-ACCESS-TIMESTAMP: 1558378899
Referer: https://localhost:44342/dashboard
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36
Response Headers:
access-control-allow-headers: Content-Type, Accept, cb-session, cb-fp
access-control-allow-methods: GET,POST,DELETE,PUT
access-control-allow-origin: *
access-control-expose-headers: cb-before, cb-after, cb-gdpr
access-control-max-age: 7200
cache-control: no-store
cf-cache-status: MISS
cf-ray: 4da08f74ba97cf68-IAD
content-length: 31
content-type: application/json; charset=utf-8
date: Mon, 20 May 2019 19:01:38 GMT
etag: W/"1f-4RjKVp8I05+xcnQ5/G16yRoMSKU"
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
status: 400
strict-transport-security: max-age=15552000; includeSubDomains
vary: Accept-Encoding
x-content-type-options: nosniff
x-dns-prefetch-control: off
x-download-options: noopen
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
Response:
{"message":"invalid signature"}
What am I doing wrong?
EDIT: Changed method to the SHA 256 version. Still doesn't work.
I ran into same issue and my code was same as yours basically. I changed to the following (c#) and it finally worked. Weird thing is coinbase pro is only exchange i have had issues with so far with the signature. In any case here is the code that worked for me. Hope this helps. Would have saved me hours
public string ComputeSignature(
HttpMethod httpMethod,
string secret,
double timestamp,
string requestUri,
string contentBody = "")
{
var convertedString = System.Convert.FromBase64String(secret);
var prehash = timestamp.ToString("F0", CultureInfo.InvariantCulture) + httpMethod.ToString().ToUpper() + requestUri + contentBody;
return HashString(prehash, convertedString);
}
private string HashString(string str, byte[] secret)
{
var bytes = Encoding.UTF8.GetBytes(str);
using (var hmaccsha = new HMACSHA256(secret))
{
return System.Convert.ToBase64String(hmaccsha.ComputeHash(bytes));
}
}
From the gdax-java (as it was named prior to "coinbase pro") library the generate signature method is:
String prehash = timestamp + method.toUpperCase() + requestPath + body;
byte[] secretDecoded = Base64.getDecoder().decode(secretKey);
keyspec = new SecretKeySpec(secretDecoded, "HmacSHA256");
sha256 = (Mac) GdaxConstants.SHARED_MAC.clone();
sha256.init(keyspec);
return Base64.getEncoder().encodeToString(sha256.doFinal(prehash.getBytes()));
At least on initial inspection the code you're using specifies using SHA512 rather than HmacSHA256, so I'd suspect that to be a probabale cause.
There is also more help with NodeJS in the right hand column here for generating the signatures. https://docs.pro.coinbase.com/#creating-a-request
Had the same issue here. For me the answer was to use luxon DateTime instead of the native js Date functions as shown in the coinbase docs.
Here is the typescript that works for me. You can use the results of this function to populate your request headers.
import crypto from 'crypto';
import { DateTime } from 'luxon';
export const auth = (
method: 'GET' | 'POST',
path: string,
body?: Record<string, unknown>
) => {
const timestamp = DateTime.utc().toMillis() / 1000;
let message = timestamp + method + path;
if (body) {
message += JSON.stringify(body);
}
const secret = Buffer.from('YOUR_SECRET','base64');
const hmac = crypto.createHmac('sha256', secret);
return {
'CB-ACCESS-KEY': 'YOUR_KEY',
'CB-ACCESS-PASSPHRASE': 'YOUR_PASSPHRASE',
'CB-ACCESS-SIGN': hmac.update(message).digest('base64'),
'CB-ACCESS-TIMESTAMP': timestamp.toString()
};
};

React Native fetch request to Microsoft Azure failing

I'm trying to use the Microsoft Azure OCR API found here for a React Native app.
I can get the API to work fine on local images with Postman, but for some reason, I get an "Unsupported Media Type" when I try using fetch within my app.
I originally called the api with this code:
_analyzeImage = () => {
const { image } = this.state;
const url = 'https://westcentralus.api.cognitive.microsoft.com/vision/v1.0/ocr';
const data = new FormData();
data.append(image);
fetch(url, {
method: 'post',
body: data,
headers: {
'Ocp-Apim-Subscription-Key': '***********************',
}
}).then(res => {
console.log(res)
});
}
Where image looks like:
That, when ran using the XCode simulator, yields:
And the response:
{
"code":"UnsupportedMediaType",
"requestId":"6ff43374-e5f9-4992-9657-82ec1e95b238",
"message": "Supported media types: application/octet-stream, multipart/form-data or application/json"
}
Weirdly, the content-type seemed to be test/plain. So, even though I thought that the FormData object was supposed to take care of content type, I tried adding 'content-type': 'multipart/form-data', but got the same response (although the content-type header in the network inspector did change to multipart/form-data.
I used create-react-native-app to set up the project, and want to to work on iOS and android. If anyone has any ideas - or any other ways to do OCR, if there's a better native solution - I'd appreciate it!
As stated in the doc page you link to, if you send
application/json, your payload must look like this:
{"url": "http://example.com/images/test.jpg"}
if application/octet-stream,
[Binary image data]
if multipart/form-data,
[Binary image data]
Right now you're not sending anything that matches expectations.
Example POST
The image,
Pass image by URL:
$ curl -v -X POST -H 'Ocp-Apim-Subscription-Key: 2exxxxxxxxxxxxxxxxxxxxxx' \
-H 'Content-type: application/json' \
--data-ascii '{ "url": "https://i.stack.imgur.com/RM7B3.png" }' \
https://westus.api.cognitive.microsoft.com/vision/v1.0/ocr
> POST /vision/v1.0/ocr HTTP/1.1
> Content-type: application/json
> Content-Length: 44
...
< HTTP/1.1 200 OK
< Content-Length: 196
< Content-Type: application/json; charset=utf-8
{
"language": "en",
...
"regions": [
{
...
"words": [
{
"boundingBox": "61,49,303,108",
"text": "hello."
}
...
or pass image by raw bytes:
$ curl -v -X POST -H 'Ocp-Apim-Subscription-Key: 2exxxxxxxxxxxxxxxxxxxxxx' \
-H 'Content-type: application/octet-stream' \
--data-binary #hello.png \
https://westus.api.cognitive.microsoft.com/vision/v1.0/ocr
> POST /vision/v1.0/ocr HTTP/1.1
> Content-type: application/octet-stream
> Content-Length: 11623
...
< HTTP/1.1 200 OK
< Content-Length: 196
< Content-Type: application/json; charset=utf-8
{
"language": "en",
...
"regions": [
{
...
"words": [
{
"boundingBox": "61,49,303,108",
"text": "hello."
}
...

How to parse an email with libetpan?

I use libetpan with C code, and I have an email in a .eml file (with 2 attachments):
MIME-Version: 1.0
Received: by 10.76.171.68 with HTTP; Mon, 2 Feb 2015 06:35:10 -0800 (PST)
Bcc: e.chizat+3#klrvi.com
Date: Mon, 2 Feb 2015 15:35:10 +0100
Delivered-To: e.chizat#klervi.com
Message-ID: <CAE2Tr_-3a+VyD4rO0YYdHqrNrPk10oMcL2G4mDLa-sFJXykrdA#mail.gmail.com>
Subject: subject
From: email#email.com
To: email#email.com
Cc: email#email.com
Content-Type: multipart/mixed; boundary=047d7b41436a901ca8050e1bdc67
--047d7b41436a901ca8050e1bdc67
Content-Type: multipart/alternative; boundary=047d7b41436a901ca3050e1bdc65
--047d7b41436a901ca3050e1bdc65
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Some text
--047d7b41436a901ca3050e1bdc65
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div>Some text</div>
--047d7b41436a901ca3050e1bdc65--
--047d7b41436a901ca8050e1bdc67
Content-Type: image/png; name="accueil.png"
Content-Disposition: attachment; filename="accueil.png"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_i5nyjma30
iVBORw0KGgoAAAANSUhEUgAAADoAAAA8CAIAAAC4gD5iAAAACXBIWXMAAAuJAAALiQE3ycutAAAA
B3RJTUUH3QoPCRUWvBfFbAAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAABJr
SURBVGje1VpfjCRHef/tXM35q6PHrjIzR9d553yNbx360BlmwU5uJSz5ECYYAdKZgIQjmcRCJEqk
OAqKUJ78YPGQtzzkAQKKUGIkYuE8YSmgHALEXuJDtxFLri325DpuJtfNbUOVdputL3t1qzz07Hrt
2/Otyf9Wa/ab2Z7u33z1+371fV/VzOgzX84zXVj3/+J15lNf+EZhHQAA7af/l+1Oi3rn/Zu2hxLR
5ymqsZ0fQguf91Gs2KwPRM5SWayU+fA/cf/X2jOjz3z5V/mtQ11YaxLkQzV/PEuNNgmBCJFLz37V
ld4zc1k7DnDMkshW7CIAyufMr+xjsRv7Pl+zVLKzf/ChfOFkns0aSgi7jrz9E8HM3nvnHTMzc+mc
nZRlzYvW5qkpqvA/wF3OUzoxkGc+dCo/lkHgNkeEb7yrnW88QABc462155bLIFRRc/vh/n18QLz9
0TzTteedX3BLu/bzR+hjp7InH3/UHB7wJo8vj8/94Ny3zn7r/D+dX/7R8uVXLvt13xXdhBJsgbcQ
Iwsheod6cTP6X9Rxi3sHSQ8G2RF145ceiPVazO8b3Oa5u+x9czfyQkZPfGD+1G+MuOGz3zn73PPP
2RWrBzo7lmXDjIh848N64MjZMFt430J+PN/xMkd2tbPWQkBKDXAIsJftuRV3oQLEfn18wLzno/vx
6w7WpR8uff7PPv+lv/7SYDD45Mc/+diHH5t/YL7f7/eSnr5Ta63pDirL8jvf/U55rTRvM13qxs2I
LUiS6KKuat6K8kA3HoC+Uyd34AY35b59vC/uzqc488iJ06
--047d7b41436a901ca8050e1bdc67
Content-Type: image/png; name="ajouter.png"
Content-Disposition: attachment; filename="ajouter.png"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_i5nyjr0o1
iVBORw0KGgoAAAANSUhEUgAAAEEAAAAkCAIAAABZrMD7AAAACXBIWXMAAAuJAAALiQE3ycutAAAA
B3RJTUUH3QoPChkHeFQUywAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAN0
SURBVFjD7VgxaBtXGP5SNDyBhhN4uAMV+iABv4DBFyyIDjL4oEPOaLFpoDF06JUOcfHQmA6t6RCU
TE4DIvagolHOYBQPIeehoCXhEki4CxiqQANvaOAOKrg3CPyGGzqckGUlVmq7bSS4b/y5d//7/vf9
//vuzh0cHGDC8QkmHymHlEPK4RCZd0N3d33X54EYu3mlKVmrRO2r+lD83NBsvbvjN5/8Ps5VX7py
8eYX+igtuft8zJXz7g6HOYyhhD64w3QupRxSDmfm4NxZbt5amhgOVM17Ndur2etfGf0gDwUPo9Ol
zOeyK+VL+Vz2/+NgFikAIaQ5S/vBlerjta3W6VIuXmF2WVdy5D/0GkOwilRKNJ+07bJuMM1tBwC8
mi1jGDfqALSp7M1rJWOaSikdn9/fcWUMZOBt2aIrze8bABo/L7GCsvDjtjlDV8o6gOatRSGk+UPj
yPIXfGPXRYwkxcOnbXmAxXm2/mur5fNTcqBqnqpK6yVvveJ2WTeLNOEw+IL7qxZVFecl13LZ6/OM
AJUH7nEv5J0oFFKdIvVHPu9EADZuWKygbO76VFOuf84iKeuPvN6JXWYA2m+FkPL0WkqE1Nrn7T+j
npyOsmaf5qmq+G/C9VprpfpYxlicZyQzwikEUVcCcF5w5xlnNM8Kiv86bPzmVbZbMoal08ECfXPP
Wb7T9IYKd6JzsIoUgDlDL13QJKDmiME0dz8Y8JJK//6XMYSQ6hTJ57JB94gjOE772pQCQJ9W3S17
MNJDDO+P4Ez9kAgJgDl3WBtTp4McAiESVwyAZKAoBPGhpSGEJEmO7GwAoisB+G/CjZ33yE+evaeT
Q9jc9et7HgBC4P5iW3Ossn2Yr82j9luhn1crX5t5JUsycJ7z/vylqrLxrZnNZcnAQQSdiH2mrF0z
gr+iyo6bLF+4zHgoVIWEHdnm0b82W3vN4Ld7VZF49jokBAbTBh9bqzqtV9ycpaygPHzarmz3Zu7t
B27YkeYsRYz6nt9/fnPP56EoTavsgoYY31Ud5zm3ivSnL0sLRRbJExvn4W8gY7XxT5Z5NVtKGKv1
j/MJUV0+2f0wBGNGs4oMQNARk+qXWEGz5igPxe3jL4GP/09gNOp7XtLiqfdOOYzmQMi47zi5T0dx
WJ6/OOYcrBL9QE/bV3XRhbs/yf/50p5OOZwWfwPhHHSIAc2xrgAAAABJRU5ErkJggg==
--047d7b41436a901ca8050e1bdc67--
My probleme is, when I conditionally display mime->mm_data.mm_single->dt_data.dt_text.dt_data (if this mime part is 'plain/texte') I get :
<div>Some text</div>
--047d7b41436a901ca3050e1bdc65--
--047d7b41436a901ca8050e1bdc67
Content-Type: image/png; name="accueil.png"
Content-Disposition: attachment; filename="accueil.png"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_i5nyjma30
iVBORw0KGgoAAAANSUhEUgAAADoAAAA8CAIAAAC4gD5iAAAACXBIWXMAAAuJAAALiQE3ycutAAAA
B3RJTUUH3QoPCRUWvBfFbAAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAABJr
SURBVGje1VpfjCRHef/tXM35q6PHrjIzR9d553yNbx360BlmwU5uJSz5ECYYAdKZgIQjmcRCJEqk
OAqKUJ78YPGQtzzkAQKKUGIkYuE8YSmgHALEXuJDtxFLri325DpuJtfNbUOVdputL3t1qzz07Hrt
2/Otyf9Wa/ab2Z7u33z1+371fV/VzOgzX84zXVj3/+J15lNf+EZhHQAA7af/l+1Oi3rn/Zu2hxLR
5ymqsZ0fQguf91Gs2KwPRM5SWayU+fA/cf/X2jOjz3z5V/mtQ11YaxLkQzV/PEuNNgmBCJFLz37V
ld4zc1k7DnDMkshW7CIAyufMr+xjsRv7Pl+zVLKzf/ChfOFkns0aSgi7jrz9E8HM3nvnHTMzc+mc
nZRlzYvW5qkpqvA/wF3OUzoxkGc+dCo/lkHgNkeEb7yrnW88QABc462155bLIFRRc/vh/n18QLz9
0TzTteedX3BLu/bzR+hjp7InH3/UHB7wJo8vj8/94Ny3zn7r/D+dX/7R8uVXLvt13xXdhBJsgbcQ
Iwsheod6cTP6X9Rxi3sHSQ8G2RF145ceiPVazO8b3Oa5u+x9czfyQkZPfGD+1G+MuOGz3zn73PPP
2RWrBzo7lmXDjIh848N64MjZMFt430J+PN/xMkd2tbPWQkBKDXAIsJftuRV3oQLEfn18wLzno/vx
6w7WpR8uff7PPv+lv/7SYDD45Mc/+diHH5t/YL7f7/eSnr5Ta63pDirL8jvf/U55rTRvM13qxs2I
LUiS6KKuat6K8kA3HoC+Uyd34AY35b59vC/uzqc488iJ06
--047d7b41436a901ca8050e1bdc67
Content-Type: image/png; name="ajouter.png"
Content-Disposition: attachment; filename="ajouter.png"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_i5nyjr0o1
iVBORw0KGgoAAAANSUhEUgAAAEEAAAAkCAIAAABZrMD7AAAACXBIWXMAAAuJAAALiQE3ycutAAAA
B3RJTUUH3QoPChkHeFQUywAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAN0
SURBVFjD7VgxaBtXGP5SNDyBhhN4uAMV+iABv4DBFyyIDjL4oEPOaLFpoDF06JUOcfHQmA6t6RCU
TE4DIvagolHOYBQPIeehoCXhEki4CxiqQANvaOAOKrg3CPyGGzqckGUlVmq7bSS4b/y5d//7/vf9
//vuzh0cHGDC8QkmHymHlEPK4RCZd0N3d33X54EYu3mlKVmrRO2r+lD83NBsvbvjN5/8Ps5VX7py
8eYX+igtuft8zJXz7g6HOYyhhD64w3QupRxSDmfm4NxZbt5amhgOVM17Ndur2etfGf0gDwUPo9Ol
zOeyK+VL+Vz2/+NgFikAIaQ5S/vBlerjta3W6VIuXmF2WVdy5D/0GkOwilRKNJ+07bJuMM1tBwC8
mi1jGDfqALSp7M1rJWOaSikdn9/fcWUMZOBt2aIrze8bABo/L7GCsvDjtjlDV8o6gOatRSGk+UPj
yPIXfGPXRYwkxcOnbXmAxXm2/mur5fNTcqBqnqpK6yVvveJ2WTeLNOEw+IL7qxZVFecl13LZ6/OM
AJUH7nEv5J0oFFKdIvVHPu9EADZuWKygbO76VFOuf84iKeuPvN6JXWYA2m+FkPL0WkqE1Nrn7T+j
npyOsmaf5qmq+G/C9VprpfpYxlicZyQzwikEUVcCcF5w5xlnNM8Kiv86bPzmVbZbMoal08ECfXPP
Wb7T9IYKd6JzsIoUgDlDL13QJKDmiME0dz8Y8JJK//6XMYSQ6hTJ57JB94gjOE772pQCQJ9W3S17
MNJDDO+P4Ez9kAgJgDl3WBtTp4McAiESVwyAZKAoBPGhpSGEJEmO7GwAoisB+G/CjZ33yE+evaeT
Q9jc9et7HgBC4P5iW3Ossn2Yr82j9luhn1crX5t5JUsycJ7z/vylqrLxrZnNZcnAQQSdiH2mrF0z
gr+iyo6bLF+4zHgoVIWEHdnm0b82W3vN4Ld7VZF49jokBAbTBh9bqzqtV9ycpaygPHzarmz3Zu7t
B27YkeYsRYz6nt9/fnPP56EoTavsgoYY31Ud5zm3ivSnL0sLRRbJExvn4W8gY7XxT5Z5NVtKGKv1
j/MJUV0+2f0wBGNGs4oMQNARk+qXWEGz5igPxe3jL4GP/09gNOp7XtLiqfdOOYzmQMi47zi5T0dx
WJ6/OOYcrBL9QE/bV3XRhbs/yf/50p5OOZwWfwPhHHSIAc2xrgAAAABJRU5ErkJggg==
--047d7b41436a901ca8050e1bdc67--
How can I just get (more or less the Content-* part):
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div>Some text</div>
mime->mm_data.mm_single->dt_data.dt_text.dt_data is the beggining of my text. I have to print it using mime->mm_data.mm_single->dt_data.dt_text.dt_length, the length of my text.

in Web API 2 how to accept simple types as post parameter along with Route parameter

Hi after some struggle I am finally got past the angular js hurdle to pass the proper parameters to my server, but the web api 2 service fails to accept it.
below is the sample code
[RoutePrefix("api/v2/bids")]
public class BidsController : ApiController
{
[Route("{quoteId:long}/accept")]
public HttpResponseMessage AcceptQuote(long quoteId,[FromBody] string remarks)
{
HttpResponseMessage response;
response = Request.CreateResponse(HttpStatusCode.Accepted, quoteId);
return response;
}
}
if you notice i have both the route parameter and also a post parameter of type sting. When I post using fiddler with the following:
POST http://127.0.0.1:81/api/v2/Bids/101/accept? HTTP/1.1
Authorization: Basic a2lyYW5AYWJjc2hpcHBlci5jb206a2lyYW5AYWJjc2hpcHBlci5jb20=
Accept: application/json, text/plain, */*
Content-Type: application/json;charset=utf-8
Referer: http://127.0.0.1:81/shipper/
Accept-Language: en-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0; EIE10;ENUSWOL)
Host: 127.0.0.1:81
Content-Length: 40
DNT: 1
Connection: Keep-Alive
Pragma: no-cache
{"remarks":"Accepting this as the best"}
or use angularjs function:
function acceptQuote(quoteId, accept_remarks, fnSuccess, fnError) {
return $resource("/api/v2/Bids/:id/accept", { quoteId: "#id"},
{ "AcceptQuote": { method: "POST", isArray: false } })
.AcceptQuote({ id: quoteId }, { remarks: accept_remarks }, fnSuccess, fnError);
}
returns the following error:
{"Message":"The request is invalid.","ModelState":{"remarks":["Error reading string. Unexpected token: StartObject. Path '', line 1, position 1."]}}
i expected that using [FromBody] was sufficient to pass the simple types as post parameters, any ideas to what else I am missing here.
The [FromBody] is working a bit differently. Please, check this Parameter Binding in ASP.NET Web API. If you'd like to get the string [FromBody] string remarks, then your body must look like:
"Accepting this as the best"
Not a JSON. On the other hand, if the body contains the JSON, the most natural way how to consume that with ASP.NET Web API, is via the Entity/Object. So, we can create this
public class MyObject
{
public string remarks { get; set; }
}
And the Controller action should look like this:
[Route("{quoteId:long}/accept")]
public HttpResponseMessage AcceptQuote(long quoteId, MyObject myObject)
{
var remarks = myObject.remarks;

Resources