I’m writing a simple test app in C# .NET8 to communicate with the DPD API. I’ve got a request which I’ve tested in Postman and it works fine (I get a 200 response with some data in the body) but when I send the same request in the C# app using the HttpClient
I just get a 400 BadRequest with an empty ReasonPhrase.
I’m connecting to the API using HTTPS in both cases. I’ve got a secuirty JWT Bearer token and it seems to be accepted in both cases. The request headers are slightly different but both look very standard and the one generated by the .NET’s HttpClient
should work too.
I only see the difference in the body – the .NET request converts quotes to u0027 but should work with every REST API too.
My questions are:
- Can I somehow use the normal quote characters instead of the u0027 in the .NET request like Postman does?
- What else could be the reason here as I don’t suppose the quotes cause the problem?
Raw request captured with Fiddler from my .NET app:
POST https://shipping.dpdgroup.com/api/v1.1/shipments HTTP/1.1 Host:
shipping.dpdgroup.com Authorization: Bearer
################################################ Transfer-Encoding: chunked Content-Type: application/json;
charset=utf-8CF7 “{ u0027buCodeu0027: u0027XXXu0027,
u0027customerIdu0027: u0027XXXXXXXu0027,
u0027shipmentsu0027: [ { u0027numOrderu0027:
52, u0027senderAddressIdu0027: u0027XXXXXu0027,
u0027receiveru0027: {
u0027additionalAddressInfou0027: u0027test shipping apiu0027,
u0027cityu0027: u0027Parisu0027,
u0027companyNameu0027: u0027DPD internal testu0027,
u0027companyName2u0027: u0027DPD 2u0027,
u0027contactEmailu0027: [email protected]u0027,
u0027contactInterphoneNameu0027: u0027u0027,
u0027contactMobileu0027: u0027777181001u0027,
u0027contactMobilePrefixu0027: u0027u0027,
u0027contactNameu0027: u0027Tomas Horcik1u0027,
u0027contactPhoneu0027: u0027777181001u0027,
u0027countryCodeu0027: u0027ITu0027,
u0027nameu0027: u0027API Tomas Horcik DPD PRIVATEu0027,
u0027streetu0027: u0027Tu00E1borsku00E1 12u0027,
u0027zipCodeu0027: u002714000u0027 },
u0027parcelsu0027: [ {
u0027dimensionHeightu0027: 25,
u0027dimensionLengthu0027: 14,
u0027dimensionWidthu0027: 13,
u0027limitedQuantityu0027: false,
u0027reference1u0027: u0027REF BALIKUtom4474u0027,
u0027reference2u0027: u0027re2 22u0027,
u0027reference3u0027: u0027re3 33u0027,
u0027reference4u0027: u0027re4 44u0027,
u0027weightu0027: 5, u0027insCurrencyu0027:
u0027u0027, u0027codCurrencyu0027:
u0027u0027 }, {
u0027dimensionHeightu0027: 25,
u0027dimensionLengthu0027: 14,
u0027dimensionWidthu0027: 13,
u0027limitedQuantityu0027: false,
u0027reference1u0027: u0027REF BALItomKU4766u0027,
u0027reference2u0027: u0027re2 22u0027,
u0027reference3u0027: u0027re3 33u0027,
u0027reference4u0027: u0027re4 44u0027,
u0027weightu0027: 5, u0027insCurrencyu0027:
u0027u0027, u0027codCurrencyu0027:
u0027u0027 } ],
u0027serviceu0027: { u0027additionalServiceu0027:
{ u0027predictsu0027: [
{ u0027destinationu0027:
u0027u002B420777181001u0027,
u0027destinationTypeu0027: u0027Consigneeu0027,
u0027typeu0027: u0027SMSu0027 }
] }, u0027mainServiceCodeu0027:
u0027u0027, u0027mainServiceElementCodesu0027: [
u0027001u0027, u0027013u0027 ]
} } ] }” 0
Raw request from Postman:
POST https://shipping.dpdgroup.com/api/v1.1/shipments HTTP/1.1 Content-Type: application/json Authorization: Bearer
################################################################### User-Agent: PostmanRuntime/7.39.0 Accept: */* Postman-Token: cefec507-260d-4691-b05f-6eaa5bfdaa6f Host: shipping.dpdgroup.com Accept-Encoding: gzip, deflate, br Connection: keep-alive Content-Length: 2514 Cookie:
_cfuvid=oAXFRBbId7Od76zIDFWaUOGouUv_rYJ31moAAsEY0EM-1718266429083-0.0.1.1-604800000
{
"buCode": "XXX",
"customerId": "XXXXXXX",
"shipments": [
{
"numOrder": 52,
"senderAddressId": "XXXXX",
"receiver": {
"additionalAddressInfo": "test shipping api",
"city": "Paris",
"companyName": "DPD internal test",
"companyName2": "DPD 2",
"contactEmail": "[email protected]",
"contactInterphoneName": "",
"contactMobile": "777181001",
"contactMobilePrefix": "",
"contactName": "Tomas Horcik1",
"contactPhone": "777181001",
"countryCode": "IT",
"name": "API Tomas Horcik DPD PRIVATE",
"street": "Táborská 12",
"zipCode": "14000"
},
"parcels": [
{
"dimensionHeight": 25,
"dimensionLength": 14,
"dimensionWidth": 13,
"limitedQuantity": false,
"reference1": "REF BALIKUtom4474",
"reference2": "re2 22",
"reference3": "re3 33",
"reference4": "re4 44",
"weight": 5,
"insCurrency": "",
"codCurrency": ""
},
{
"dimensionHeight": 25,
"dimensionLength": 14,
"dimensionWidth": 13,
"limitedQuantity": false,
"reference1": "REF BALItomKU4766",
"reference2": "re2 22",
"reference3": "re3 33",
"reference4": "re4 44",
"weight": 5,
"insCurrency": "",
"codCurrency": ""
}
],
"service": {
"additionalService": {
"predicts": [
{
"destination": "+420777181001",
"destinationType": "Consignee",
"type": "SMS"
}
]
},
"mainServiceCode": "",
"mainServiceElementCodes": [
"001",
"013"
]
}
}
] }