-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to call Web API 2 Batch Endpoint #36
Comments
Looks like you need to setup CORS. The first call is an option request. On 00:53, Wed, 6 Jul 2016 venkatesh-bhupathi, notifications@github.com
|
You will first need to enable CORS (needed for the angular client to talk to your service across different domains).
Then enable HTTP batching.
|
I am trying to use http batcher sample code to call batch endpoint on ASP .Net Web API 2, but not able to make the batch calls. I am able to call the same batch endpoint with .Net client code without any issues.
Following is the fiddler trace when calling through http batcher,
Request:
OPTIONS http://localhost:84/api/batch HTTP/1.1
Host: devx.microsoft-tst.com:84
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://localhost:2019
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
Access-Control-Request-Headers: accept, content-type
Accept: /
Referer: http://localhost:2019/Home/Index
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Response:
HTTP/1.1 400 Bad Request
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 05 Jul 2016 14:44:43 GMT
Content-Length: 68
{"Message":"The batch request must have a "Content-Type" header."}
Following is the fiddler trace for .Net client,
POST http://localhost:84/api/batch HTTP/1.1
Content-Type: multipart/mixed; boundary="batch_75e852a8-ae17-4cf7-a601-1e3dbfd47f5c"
Host: localhost:84
Content-Length: 857
Expect: 100-continue
Connection: Keep-Alive
--batch_75e852a8-ae17-4cf7-a601-1e3dbfd47f5c
Content-Type: application/http; msgtype=request
GET /api/Customers HTTP/1.1
Host: localhost:84
--batch_75e852a8-ae17-4cf7-a601-1e3dbfd47f5c
Content-Type: application/http; msgtype=request
POST /api/Customers HTTP/1.1
Host: localhost:84
Content-Type: application/json; charset=utf-8
{"Id":10,"Name":"Name 10"}
--batch_75e852a8-ae17-4cf7-a601-1e3dbfd47f5c
Content-Type: application/http; msgtype=request
PUT /api/Customers/100 HTTP/1.1
Host: localhost:84
Content-Type: application/json; charset=utf-8
{"Id":100,"Name":"Peter"}
--batch_75e852a8-ae17-4cf7-a601-1e3dbfd47f5c
Content-Type: application/http; msgtype=request
DELETE /api/Customers/100 HTTP/1.1
Host: localhost:84
--batch_75e852a8-ae17-4cf7-a601-1e3dbfd47f5c--
Response
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 795
Content-Type: multipart/mixed; boundary="1c3e08bd-7545-4b3a-bd0d-b291a436a7fb"
Expires: -1
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 05 Jul 2016 12:10:19 GMT
--1c3e08bd-7545-4b3a-bd0d-b291a436a7fb
Content-Type: application/http; msgtype=response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
[{"Id":100,"Name":"Venkatesh"}]
--1c3e08bd-7545-4b3a-bd0d-b291a436a7fb
Content-Type: application/http; msgtype=response
HTTP/1.1 201 Created
Location: http://localhost:84/api/Customers
Content-Type: application/json; charset=utf-8
{"Id":100,"Name":"Venkatesh"}
--1c3e08bd-7545-4b3a-bd0d-b291a436a7fb
Content-Type: application/http; msgtype=response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{"Id":100,"Name":"Venkatesh"}
--1c3e08bd-7545-4b3a-bd0d-b291a436a7fb
Content-Type: application/http; msgtype=response
HTTP/1.1 204 No Content
--1c3e08bd-7545-4b3a-bd0d-b291a436a7fb--
The text was updated successfully, but these errors were encountered: