Chrome webrequest doesn't see POST data in requestBody - javascript

I am having a problem getting the POST data from a Facebook action. When you submit a comment on FB it posts to this url: https://www.facebook.com/ufi/add/comment/?__pc=EXP1%3ADEFAULT
In the request, the post data for the post exists:
Here is an example of the actual comment from the post data:
comment_text:test this is a test
When I try to access this through a Chrome Extension I can't seem to get this data. I've tried parsing the requestBody, but it is empty. I then tried to see if any of the other requestmethods would work, and I can't seem to find the data anywhere.
manifest.json:
{
"background": {
"scripts": [ "background.js" ]
},
"manifest_version": 2,
"name": "Interaction Tracker",
"description": "Track social interactions by social site and customizable categories.",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [ "webRequest", "webRequestBlocking", "webNavigation", "tabs", "<all_urls>", "debugger" ]
}
background.js
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (details.method == "POST") {
var fb_add_comment_regex = new RegExp(".*facebook\.com\/ufi\/add\/comment.*");
if ( fb_add_comment_regex.test(details.url) ) {
console.log(JSON.stringify(details));
}
}
},
{urls: ["<all_urls>"]},
["blocking", "requestBody"]
);
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
if (details.method == "POST") {
var fb_add_comment_regex = new RegExp(".*facebook\.com\/ufi\/add\/comment.*");
if ( fb_add_comment_regex.test(details.url) ) {
console.log(JSON.stringify(details));
}
}
},
{urls: ["<all_urls>"]},
["blocking", "requestHeaders"]
);
chrome.webRequest.onSendHeaders.addListener(
function(details) {
if (details.method == "POST") {
var fb_add_comment_regex = new RegExp(".*facebook\.com\/ufi\/add\/comment.*");
if ( fb_add_comment_regex.test(details.url) ) {
console.log(JSON.stringify(details));
}
}
},
{urls: ["<all_urls>"]},
["requestHeaders"]
);
chrome.webRequest.onHeadersReceived.addListener(
function(details) {
if (details.method == "POST") {
var fb_add_comment_regex = new RegExp(".*facebook\.com\/ufi\/add\/comment.*");
if ( fb_add_comment_regex.test(details.url) ) {
console.log(JSON.stringify(details));
}
}
},
{urls: ["<all_urls>"]},
["blocking", "responseHeaders"]
);
chrome.webRequest.onAuthRequired.addListener(
function(details) {
if (details.method == "POST") {
var fb_add_comment_regex = new RegExp(".*facebook\.com\/ufi\/add\/comment.*");
if ( fb_add_comment_regex.test(details.url) ) {
console.log(JSON.stringify(details));
}
}
},
{urls: ["<all_urls>"]},
["blocking", "responseHeaders"]
);
chrome.webRequest.onResponseStarted.addListener(
function(details) {
if (details.method == "POST") {
var fb_add_comment_regex = new RegExp(".*facebook\.com\/ufi\/add\/comment.*");
if ( fb_add_comment_regex.test(details.url) ) {
console.log(JSON.stringify(details));
}
}
},
{urls: ["<all_urls>"]},
["responseHeaders"]
);
chrome.webRequest.onBeforeRedirect.addListener(
function(details) {
if (details.method == "POST") {
var fb_add_comment_regex = new RegExp(".*facebook\.com\/ufi\/add\/comment.*");
if ( fb_add_comment_regex.test(details.url) ) {
console.log(JSON.stringify(details));
}
}
},
{urls: ["<all_urls>"]},
["responseHeaders"]
);
chrome.webRequest.onCompleted.addListener(
function(details) {
if (details.method == "POST") {
var fb_add_comment_regex = new RegExp(".*facebook\.com\/ufi\/add\/comment.*");
if ( fb_add_comment_regex.test(details.url) ) {
console.log(JSON.stringify(details));
}
}
},
{urls: ["<all_urls>"]},
["responseHeaders"]
);
Below is the output from the console.log statements for each type of request:
onBeforeRequest
{
"frameId": 0,
"method": "POST",
"parentFrameId": -1,
"requestBody": {
"raw": [
{
"bytes": {
}
}
]
},
"requestId": "6724",
"tabId": 93,
"timeStamp": 1444749653166.1,
"type": "xmlhttprequest",
"url": "https:\/\/www.facebook.com\/ufi\/add\/comment\/?__pc=EXP1%3ADEFAULT"
}
onBeforeSendHeaders
{
"frameId": 0,
"method": "POST",
"parentFrameId": -1,
"requestHeaders": [
{
"name": "Origin",
"value": "https:\/\/www.facebook.com"
},
{
"name": "X-DevTools-Emulate-Network-Conditions-Client-Id",
"value": "AB63796C-002A-4670-8A56-547F8D13CA8C"
},
{
"name": "User-Agent",
"value": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/45.0.2454.101 Safari\/537.36"
},
{
"name": "Content-Type",
"value": "application\/x-www-form-urlencoded"
},
{
"name": "Accept",
"value": "*\/*"
},
{
"name": "Referer",
"value": "https:\/\/www.facebook.com\/GrauZug?ref=br_rs"
},
{
"name": "Accept-Encoding",
"value": "gzip, deflate"
},
{
"name": "Accept-Language",
"value": "en-US,en;q=0.8"
},
{
"name": "Cookie",
"value": "datr=pvA2VDnTeMjGlWhVYRrnhBtO; lu=gh2TS-IuZkO-Ku-YhAzkiFIw; p=-2; c_user=100000720140344; fr=07LqqXcCamvBIa9Ww.AWU6e_qoHRglPj51gS-CF6uF-r8.BVY1Qk.DT.FYB.0.AWVvgvJA; xs=79%3A403i2b7V6bYSIA%3A2%3A1439311770%3A8344; csm=2; s=Aa4bsJIf94u-JaGr.BVyieb; presence=EDvF3EtimeF1444749507EuserFA21B00720140344A2EstateFDsb2F1444656454966Et2F_5b_5dElm2FnullEuct2F1444743344BEtrFnullEtwF2707054892EatF1444748467285G444749507665CEchFDp_5f1B00720140344F101CC; act=1444749649564%2F26"
}
],
"requestId": "6724",
"tabId": 93,
"timeStamp": 1444749653173.2,
"type": "xmlhttprequest",
"url": "https:\/\/www.facebook.com\/ufi\/add\/comment\/?__pc=EXP1%3ADEFAULT"
}
onSendHeaders
{
"frameId": 0,
"method": "POST",
"parentFrameId": -1,
"requestHeaders": [
{
"name": "Origin",
"value": "https:\/\/www.facebook.com"
},
{
"name": "X-DevTools-Emulate-Network-Conditions-Client-Id",
"value": "AB63796C-002A-4670-8A56-547F8D13CA8C"
},
{
"name": "User-Agent",
"value": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/45.0.2454.101 Safari\/537.36"
},
{
"name": "Content-Type",
"value": "application\/x-www-form-urlencoded"
},
{
"name": "Accept",
"value": "*\/*"
},
{
"name": "Referer",
"value": "https:\/\/www.facebook.com\/GrauZug?ref=br_rs"
},
{
"name": "Accept-Encoding",
"value": "gzip, deflate"
},
{
"name": "Accept-Language",
"value": "en-US,en;q=0.8"
},
{
"name": "Cookie",
"value": "datr=pvA2VDnTeMjGlWhVYRrnhBtO; lu=gh2TS-IuZkO-Ku-YhAzkiFIw; p=-2; c_user=100000720140344; fr=07LqqXcCamvBIa9Ww.AWU6e_qoHRglPj51gS-CF6uF-r8.BVY1Qk.DT.FYB.0.AWVvgvJA; xs=79%3A403i2b7V6bYSIA%3A2%3A1439311770%3A8344; csm=2; s=Aa4bsJIf94u-JaGr.BVyieb; presence=EDvF3EtimeF1444749507EuserFA21B00720140344A2EstateFDsb2F1444656454966Et2F_5b_5dElm2FnullEuct2F1444743344BEtrFnullEtwF2707054892EatF1444748467285G444749507665CEchFDp_5f1B00720140344F101CC; act=1444749649564%2F26"
}
],
"requestId": "6724",
"tabId": 93,
"timeStamp": 1444749653175.2,
"type": "xmlhttprequest",
"url": "https:\/\/www.facebook.com\/ufi\/add\/comment\/?__pc=EXP1%3ADEFAULT"
}
onHeadersReceived
{
"frameId": 0,
"method": "POST",
"parentFrameId": -1,
"requestId": "6724",
"responseHeaders": [
{
"name": "status",
"value": "200"
},
{
"name": "cache-control",
"value": "private, no-cache, no-store, must-revalidate"
},
{
"name": "content-encoding",
"value": "gzip"
},
{
"name": "content-security-policy",
"value": "default-src * data: blob:;script-src *.facebook.com *.fbcdn.net *.facebook.net *.google-analytics.com *.virtualearth.net *.google.com 127.0.0.1:* *.spotilocal.com:* 'unsafe-inline' 'unsafe-eval' *.akamaihd.net *.atlassolutions.com blob: chrome-extension:\/\/lifbcibllhkdhoafpjfnlhfpfgnpldfl;style-src * 'unsafe-inline';connect-src *.facebook.com *.fbcdn.net *.facebook.net *.spotilocal.com:* *.akamaihd.net wss:\/\/*.facebook.com:* https:\/\/fb.scanandcleanlocal.com:* *.atlassolutions.com attachment.fbsbx.com 127.0.0.1:*;"
},
{
"name": "content-type",
"value": "application\/x-javascript; charset=utf-8"
},
{
"name": "date",
"value": "Tue, 13 Oct 2015 15:20:55 GMT"
},
{
"name": "expires",
"value": "Sat, 01 Jan 2000 00:00:00 GMT"
},
{
"name": "pragma",
"value": "no-cache"
},
{
"name": "public-key-pins-report-only",
"value": "max-age=500; pin-sha256=\"WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18=\"; pin-sha256=\"r\/mIkG3eEpVdm+u\/ko\/cwxzOMo1bk4TyHIlByibiA5E=\"; pin-sha256=\"q4PO2G2cbkZhZ82+JgmRUyGMoAeozA+BSXVXQWB8XWQ=\"; report-uri=\"http:\/\/reports.fb.com\/hpkp\/\""
},
{
"name": "strict-transport-security",
"value": "max-age=15552000; preload"
},
{
"name": "vary",
"value": "Accept-Encoding"
},
{
"name": "x-content-type-options",
"value": "nosniff"
},
{
"name": "x-fb-debug",
"value": "fd7Bt\/uIX2rLmngndhprmXlX3mTkZboQqcPSaw9kQt0aQUEfX3ikBMT1016i1c2RPbts9Jhbb0+bVGWPqk\/j7Q=="
},
{
"name": "x-frame-options",
"value": "DENY"
},
{
"name": "x-xss-protection",
"value": "0"
}
],
"statusCode": 200,
"statusLine": "HTTP\/1.1 200 OK",
"tabId": 93,
"timeStamp": 1444749655679.6,
"type": "xmlhttprequest",
"url": "https:\/\/www.facebook.com\/ufi\/add\/comment\/?__pc=EXP1%3ADEFAULT"
}
onResponseStarted
{
"frameId": 0,
"fromCache": false,
"ip": "31.13.93.3",
"method": "POST",
"parentFrameId": -1,
"requestId": "6724",
"responseHeaders": [
{
"name": "status",
"value": "200"
},
{
"name": "cache-control",
"value": "private, no-cache, no-store, must-revalidate"
},
{
"name": "content-encoding",
"value": "gzip"
},
{
"name": "content-security-policy",
"value": "default-src * data: blob:;script-src *.facebook.com *.fbcdn.net *.facebook.net *.google-analytics.com *.virtualearth.net *.google.com 127.0.0.1:* *.spotilocal.com:* 'unsafe-inline' 'unsafe-eval' *.akamaihd.net *.atlassolutions.com blob: chrome-extension:\/\/lifbcibllhkdhoafpjfnlhfpfgnpldfl;style-src * 'unsafe-inline';connect-src *.facebook.com *.fbcdn.net *.facebook.net *.spotilocal.com:* *.akamaihd.net wss:\/\/*.facebook.com:* https:\/\/fb.scanandcleanlocal.com:* *.atlassolutions.com attachment.fbsbx.com 127.0.0.1:*;"
},
{
"name": "content-type",
"value": "application\/x-javascript; charset=utf-8"
},
{
"name": "date",
"value": "Tue, 13 Oct 2015 15:20:55 GMT"
},
{
"name": "expires",
"value": "Sat, 01 Jan 2000 00:00:00 GMT"
},
{
"name": "pragma",
"value": "no-cache"
},
{
"name": "public-key-pins-report-only",
"value": "max-age=500; pin-sha256=\"WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18=\"; pin-sha256=\"r\/mIkG3eEpVdm+u\/ko\/cwxzOMo1bk4TyHIlByibiA5E=\"; pin-sha256=\"q4PO2G2cbkZhZ82+JgmRUyGMoAeozA+BSXVXQWB8XWQ=\"; report-uri=\"http:\/\/reports.fb.com\/hpkp\/\""
},
{
"name": "strict-transport-security",
"value": "max-age=15552000; preload"
},
{
"name": "vary",
"value": "Accept-Encoding"
},
{
"name": "x-content-type-options",
"value": "nosniff"
},
{
"name": "x-fb-debug",
"value": "fd7Bt\/uIX2rLmngndhprmXlX3mTkZboQqcPSaw9kQt0aQUEfX3ikBMT1016i1c2RPbts9Jhbb0+bVGWPqk\/j7Q=="
},
{
"name": "x-frame-options",
"value": "DENY"
},
{
"name": "x-xss-protection",
"value": "0"
}
],
"statusCode": 200,
"statusLine": "HTTP\/1.1 200 OK",
"tabId": 93,
"timeStamp": 1444749655683.3,
"type": "xmlhttprequest",
"url": "https:\/\/www.facebook.com\/ufi\/add\/comment\/?__pc=EXP1%3ADEFAULT"
}
onCompleted
{
"frameId": 0,
"fromCache": false,
"ip": "31.13.93.3",
"method": "POST",
"parentFrameId": -1,
"requestId": "6724",
"responseHeaders": [
{
"name": "status",
"value": "200"
},
{
"name": "cache-control",
"value": "private, no-cache, no-store, must-revalidate"
},
{
"name": "content-encoding",
"value": "gzip"
},
{
"name": "content-security-policy",
"value": "default-src * data: blob:;script-src *.facebook.com *.fbcdn.net *.facebook.net *.google-analytics.com *.virtualearth.net *.google.com 127.0.0.1:* *.spotilocal.com:* 'unsafe-inline' 'unsafe-eval' *.akamaihd.net *.atlassolutions.com blob: chrome-extension:\/\/lifbcibllhkdhoafpjfnlhfpfgnpldfl;style-src * 'unsafe-inline';connect-src *.facebook.com *.fbcdn.net *.facebook.net *.spotilocal.com:* *.akamaihd.net wss:\/\/*.facebook.com:* https:\/\/fb.scanandcleanlocal.com:* *.atlassolutions.com attachment.fbsbx.com 127.0.0.1:*;"
},
{
"name": "content-type",
"value": "application\/x-javascript; charset=utf-8"
},
{
"name": "date",
"value": "Tue, 13 Oct 2015 15:20:55 GMT"
},
{
"name": "expires",
"value": "Sat, 01 Jan 2000 00:00:00 GMT"
},
{
"name": "pragma",
"value": "no-cache"
},
{
"name": "public-key-pins-report-only",
"value": "max-age=500; pin-sha256=\"WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18=\"; pin-sha256=\"r\/mIkG3eEpVdm+u\/ko\/cwxzOMo1bk4TyHIlByibiA5E=\"; pin-sha256=\"q4PO2G2cbkZhZ82+JgmRUyGMoAeozA+BSXVXQWB8XWQ=\"; report-uri=\"http:\/\/reports.fb.com\/hpkp\/\""
},
{
"name": "strict-transport-security",
"value": "max-age=15552000; preload"
},
{
"name": "vary",
"value": "Accept-Encoding"
},
{
"name": "x-content-type-options",
"value": "nosniff"
},
{
"name": "x-fb-debug",
"value": "fd7Bt\/uIX2rLmngndhprmXlX3mTkZboQqcPSaw9kQt0aQUEfX3ikBMT1016i1c2RPbts9Jhbb0+bVGWPqk\/j7Q=="
},
{
"name": "x-frame-options",
"value": "DENY"
},
{
"name": "x-xss-protection",
"value": "0"
}
],
"statusCode": 200,
"statusLine": "HTTP\/1.1 200 OK",
"tabId": 93,
"timeStamp": 1444749655684.2,
"type": "xmlhttprequest",
"url": "https:\/\/www.facebook.com\/ufi\/add\/comment\/?__pc=EXP1%3ADEFAULT"
}
Any other listener not listed above didn't have output.
Anyone have any idea here?

Your console.log shows that requestBody is not empty.
You'll just have to parse the raw bytes:
If the request method is PUT or POST, and the body is not already parsed in formData, then the unparsed request body elements are contained in this array.
For example if the posted data is a string then you can get its value in onBeforeRequest listener:
var postedString = decodeURIComponent(String.fromCharCode.apply(null,
new Uint8Array(details.requestBody.raw[0].bytes)));
There are many methods to decode the string depending on the encoding used by the site script.

Another reason why the request body might not be present is because extraInfoSpec must contain 'requestBody' as per below.
chrome.webRequest.onBeforeRequest.addListener(
function(details)
{
console.log(details.requestBody);
},
{urls: ["https://myurlhere.com/*"]},
['requestBody']
);

Related

how to write multiple file using recursive function

i wanna write file in one call but i cant looping for creating path.
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
to many statment if i using condition to create new file
asyncForEach(items, async (element) => {
if(element.hasOwnProperty('item')){
const path = 'tests/'+element.name;
console.log(path);
fs.mkdirSync(path, { recursive: true })
// await waitFor(50)
asyncForEach(element.item, async (second) => {
const second_path = path
if(second.hasOwnProperty('item') == false){
// console.log(second.name)
write(second, path, contents)
this is the input JSON
{
"info": {
"_postman_id": "fcf35761-60a4-44e8-adf9-cb871a823e38",
"name": "Reqres In",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Users",
"item": [
{
"name": "LIST USERS",
"event": [
{
"listen": "test",
"script": {
"id": "17155c09-d1cd-467c-8d45-94d2c0f7d728",
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{URL}}/api/users",
"host": [
"{{URL}}"
],
"path": [
"api",
"users"
]
}
},
"response": []
},
{
"name": "SINGLE USER",
"event": [
{
"listen": "test",
"script": {
"id": "3b1d6983-204f-4da7-a901-4ee4bfd6b69d",
"exec": [
"pm.test(\"Status code is 201\", function () {",
" pm.response.to.have.status(200);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{URL}}/api/users/2",
"host": [
"{{URL}}"
],
"path": [
"api",
"users",
"2"
]
}
},
"response": []
},
{
"name": "SINGLE USER NOT FOUND",
"event": [
{
"listen": "test",
"script": {
"id": "9e63a01c-a60a-4ac8-ac25-2e2d99614781",
"exec": [
"pm.test(\"Status code is 404\", function () {",
" pm.response.to.have.status(404);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{URL}}/api/users/23",
"host": [
"{{URL}}"
],
"path": [
"api",
"users",
"23"
]
}
},
"response": []
}
],
"protocolProfileBehavior": {}
},
{
"name": "Create",
"item": [
{
"name": "CREATE",
"event": [
{
"listen": "test",
"script": {
"id": "35b3b52e-3dfa-4503-8437-1c826a60f283",
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"john doe\",\n \"job\": \"leader\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{URL}}/api/users",
"host": [
"{{URL}}"
],
"path": [
"api",
"users"
]
}
},
"response": []
},
{
"name": "UPDATE - PUT",
"event": [
{
"listen": "test",
"script": {
"id": "34b75157-7d92-486b-80fc-f14ffbde2870",
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "PUT",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{URL}}/api/users/2",
"host": [
"{{URL}}"
],
"path": [
"api",
"users",
"2"
]
}
},
"response": []
}
],
"protocolProfileBehavior": {}
},
{
"name": "Registrasi",
"item": [
{
"name": "Registrasi Success",
"event": [
{
"listen": "test",
"script": {
"id": "e1ca180d-406b-4577-bdff-bfa90409e3b0",
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"{{email}}\",\n \"password\": \"pistol\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{URL}}/api/register",
"host": [
"{{URL}}"
],
"path": [
"api",
"register"
]
}
},
"response": []
},
{
"name": "Registrasi Failed",
"event": [
{
"listen": "test",
"script": {
"id": "83cad3df-b243-4822-a359-5881a8573319",
"exec": [
"pm.test(\"Status code is 400\", function () {",
" pm.response.to.have.status(400);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"sydney#fife\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{URL}}/api/register",
"host": [
"{{URL}}"
],
"path": [
"api",
"register"
]
}
},
"response": []
}
],
"protocolProfileBehavior": {}
},
{
"name": "Login",
"item": [
{
"name": "LOGIN - SUCCESSFUL",
"event": [
{
"listen": "test",
"script": {
"id": "510fc7b5-3a1f-41c4-932f-c7865c693aa6",
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"var jsonData = JSON.parse(responseBody);",
"pm.environment.set(\"token\", jsonData.token);"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"eve.holt#reqres.in\",\n \"password\": \"cityslicka\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{URL}}/api/login",
"host": [
"{{URL}}"
],
"path": [
"api",
"login"
]
}
},
"response": []
},
{
"name": "LOGIN - UNSUCCESSFUL",
"event": [
{
"listen": "test",
"script": {
"id": "4bb57fea-29ab-4e61-a21c-deb0b2a9cd9a",
"exec": [
"pm.test(\"Status code is 400\", function () {",
" pm.response.to.have.status(400);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"peter#klaven\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{URL}}/api/login",
"host": [
"{{URL}}"
],
"path": [
"api",
"login"
]
}
},
"response": []
}
],
"protocolProfileBehavior": {}
}
],
"protocolProfileBehavior": {}
}
i guess this is what you wan't, to recursively add path when meet dir, write to file when it's leaf node, while not aware of your logic detail, this is a demo code just to clarify how to transform your code to recursive model.
please check ,any more question leave your comment:
async doFileWriteJob(array, path) {
for (let index = 0; index < array.length; index++) {
element = array[index]
if(element.hasOwnProperty('item')){
if(!path) {
path = 'tests'
} else {
path = path + '/' + element.name;
}
console.log(path);
if(element.item && element.item.length > 0) {
fs.mkdirSync(path, { recursive: true })
// await waitFor(50)
doFileWriteJob(element.item, path)
} else {
if(element.hasOwnProperty('item') == false){
// console.log(element.name)
write(element, path, element.contents)
}
}
}
}
})
doFileWriteJob(array, '');

How to debug 406 HTTP response in client side JS?

I am making a POST request from my web app to a local instance of elasticsearch. If I run the POST request with curl, I get an appropriate response:
curl -XPOST "http://localhost:9200/my-index/_search" -H'content-type: application/json'
-d'{
"highlight": {
"fragment_size": 200,
"number_of_fragments": 1,
"fields": {
"title": {},
"description": {}
}
},
"_source": [
"id",
"nps_link",
"title",
"description"
],
"aggs": {
"states": {
"terms": {
"field": "states.keyword",
"size": 30
}
},
"world_heritage_site": {
"terms": {
"field": "world_heritage_site"
}
},
"visitors": {
"range": {
"field": "visitors",
"ranges": [
{
"from": 0,
"to": 10000,
"key": "0 - 10000"
},
{
"from": 10001,
"to": 100000,
"key": "10001 - 100000"
},
{
"from": 100001,
"to": 500000,
"key": "100001 - 500000"
},
{
"from": 500001,
"to": 1000000,
"key": "500001 - 1000000"
},
{
"from": 1000001,
"to": 5000000,
"key": "1000001 - 5000000"
},
{
"from": 5000001,
"to": 10000000,
"key": "5000001 - 10000000"
},
{
"from": 10000001,
"key": "10000001+"
}
]
}
},
"acres": {
"range": {
"field": "acres",
"ranges": [
{
"from": -1,
"key": "Any"
},
{
"from": 0,
"to": 1000,
"key": "Small"
},
{
"from": 1001,
"to": 100000,
"key": "Medium"
},
{
"from": 100001,
"key": "Large"
}
]
}
}
},
"query": {
"bool": {
"must": [
{
"match_all": {}
}
]
}
},
"size": 20
}'
Yet, when I make the POST request using fetch, I get the error POST http://localhost:9200/my-index/_search net::ERR_ABORTED 406 (Not Acceptable). How can I view the Accept header format that elastic search is responding with? For reference, my JS code is below:
const response = await fetch("http://localhost:9200/my-index/_search", {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
mode: 'no-cors',
body: JSON.stringify(body),
});
Any thoughts? Thank you!

Get a value from Nested JSON

I am completely new to Node.js. I have to read specific value from a API responded Nested JSON. I have tried to figure out but getting Undefined instead of the value. Whenever I am trying to read the base object I am getting the responded value but whenever I am trying to read the object under array then I am getting Undefined value.
Code Snippet:
var https = require('https');
var optionget = {
host: 'api-dev.dataoverflow.com',
port: 443,
path: '/test1/test2/',
method: 'GET',
HEADERS: {
'Authorization': 'Basic grege==',
'X-PruAppID : '
PlainCardPortal '
}
};
console.info(optionsget)
var reqGet = htttps.request(optionsget, function(res) {
console.log("statusCode: ", res.statusCode);
res.on('data', function(d) {
process.stdout.write(d);
process.stdout.write(jsonobj);
var Value = jsonobj.items.item.topping.type;
console.log(Value)
});
});
reqGet.end();
reqGet.on('error', function(e) {
console.error(e);
});
var optionsgetmsg = {
host: 'api-dev.dataoverflow.com',
port: 443,
method: 'GET'
};
console.info(optionsgetmsg);
var reqGet = https.request(optionsget, function(res) {
console.log("statusCode: ", res.statusCode);
res.setEncoding('utf-8')
res.on('data', function(data) {
process.stdout.write(data);
});
});
reqGet.end();
reqGet.on('error', function(e) {
console.error(e);
});
Nested JSON Snippet:
{
"items":
{
"item":
[
{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" },
{ "id": "1004", "type": "Devil's Food" }
]
},
"topping":
[
{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" },
{ "id": "5007", "type": "Powdered Sugar" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
},
...
]
}
}
I want to read type : Glazed from this JSON only but I am getting Undefined.
You have to iterate over the values in an array. You cannot access them using . notation. Use map to iterate over the array and get they types in the topping array
var jsonobj = {
"items": {
"item": [{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters": {
"batter": [{
"id": "1001",
"type": "Regular"
},
{
"id": "1002",
"type": "Chocolate"
},
{
"id": "1003",
"type": "Blueberry"
},
{
"id": "1004",
"type": "Devil's Food"
}
]
},
"topping": [{
"id": "5001",
"type": "None"
},
{
"id": "5002",
"type": "Glazed"
},
{
"id": "5005",
"type": "Sugar"
},
{
"id": "5007",
"type": "Powdered Sugar"
},
{
"id": "5006",
"type": "Chocolate with Sprinkles"
},
{
"id": "5003",
"type": "Chocolate"
},
{
"id": "5004",
"type": "Maple"
}
]
}
]
}
}
var Value = jsonobj.items.item.map(e=>e.topping)[0].map(x=>x.type);
console.log(...Value)

Using the AWS API Gateway SDK for Javascript

I'm trying to use the AmzaonWebService Api Gateway SDK for Javascript without success.
I've all the time the console error message : "Access Control Allow origin missing"
This is how I do:
dataFactory.setConfig = function() {
var config = {
accessKey: 'xxxxxxxxxxxxxx', // AWS Access KEY ID
secretKey: 'xxxxxxxxxx/xxxxxxxxxx/xxxxxxxx', // AWS Secret Key ID
sessionToken: dataFactory.getCognitoCredentials().idToken.jwtToken,
region: 'eu-west-1',
apiKey: undefined,
defaultContentType: 'application/json',
defaultAcceptType: 'application/json'
};
return config
}
var apigClient = apigClientFactory.newClient(dataFactory.setConfig());
dataFactory.getAll = function() {
var params = {
headers: {
"Access-Control-Allow-Origin": "*"
}
}
apigClient.allGet(params).then(function(res) {
console.log(res);
return res
}).catch(function(res) {
console.log(res);
})
};
This is how I'm getting the credentials:
dataFactory.getCognitoCredentials = function() {
var res;
var poolData = {
UserPoolId: 'eu-west-1_xxxxxxxx',
ClientId: 'xxxxxxxxxxxxxxx'
};
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
var cognitoUser = userPool.getCurrentUser();
if (cognitoUser != null) {
cognitoUser.getSession(function(err, session) {
if (err) {
alert(err);
return;
}
res = session
});
}
return res;
}
Does someone know what I'm doing wrong ?
You need to setup the CORS headers on API Gateway's response and an OPTION method as a pre-flight method. I have an example swagger file which has CORS setup. You might want to take a look.
{
"swagger": "2.0",
"info": {
"description": "Your first API with Amazon API Gateway. This is a sample API that integrates via HTTP with our demo Pet Store endpoints",
"title": "PetStore"
},
"schemes": [
"https"
],
"paths": {
"/": {
"get": {
"tags": [
"pets"
],
"description": "PetStore HTML web page containing API usage information",
"consumes": [
"application/json"
],
"produces": [
"text/html"
],
"responses": {
"200": {
"description": "Successful operation",
"headers": {
"Content-Type": {
"type": "string",
"description": "Media type of request"
}
}
}
},
"x-amazon-apigateway-integration": {
"responses": {
"default": {
"statusCode": "200",
"responseParameters": {
"method.response.header.Content-Type": "'text/html'"
},
"responseTemplates": {
"text/html": "<html>\n <head>\n <style>\n body {\n color: #333;\n font-family: Sans-serif;\n max-width: 800px;\n margin: auto;\n }\n </style>\n </head>\n <body>\n <h1>Welcome to your Pet Store API</h1>\n <p>\n You have succesfully deployed your first API. You are seeing this HTML page because the <code>GET</code> method to the root resource of your API returns this content as a Mock integration.\n </p>\n <p>\n The Pet Store API contains the <code>/pets</code> and <code>/pets/{petId}</code> resources. By making a <code>GET</code> request to <code>/pets</code> you can retrieve a list of Pets in your API. If you are looking for a specific pet, for example the pet with ID 1, you can make a <code>GET</code> request to <code>/pets/1</code>.\n </p>\n <p>\n You can use a REST client such as Postman to test the <code>POST</code> methods in your API to create a new pet. Use the sample body below to send the <code>POST</code> request:\n </p>\n <pre>\n{\n \"type\" : \"cat\",\n \"price\" : 123.11\n}\n </pre>\n </body>\n</html>"
}
}
},
"passthroughBehavior": "when_no_match",
"requestTemplates": {
"application/json": "{\"statusCode\": 200}"
},
"type": "mock"
}
}
},
"/pets": {
"get": {
"tags": [
"pets"
],
"summary": "List all pets",
"produces": [
"application/json"
],
"parameters": [
{
"name": "type",
"in": "query",
"description": "The type of pet to retrieve",
"required": false,
"type": "string"
},
{
"name": "page",
"in": "query",
"description": "Page number of results to return.",
"required": false,
"type": "string"
}
],
"responses": {
"200": {
"description": "Successful operation",
"schema": {
"$ref": "#/definitions/Pets"
},
"headers": {
"Access-Control-Allow-Origin": {
"type": "string",
"description": "URI that may access the resource"
}
}
}
},
"x-amazon-apigateway-integration": {
"responses": {
"default": {
"statusCode": "200",
"responseParameters": {
"method.response.header.Access-Control-Allow-Origin": "'*'"
}
}
},
"requestParameters": {
"integration.request.querystring.page": "method.request.querystring.page",
"integration.request.querystring.type": "method.request.querystring.type"
},
"uri": "http://petstore-demo-endpoint.execute-api.com/petstore/pets",
"passthroughBehavior": "when_no_match",
"httpMethod": "GET",
"type": "http"
}
},
"post": {
"tags": [
"pets"
],
"operationId": "CreatePet",
"summary": "Create a pet",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "body",
"name": "NewPet",
"required": true,
"schema": {
"$ref": "#/definitions/NewPet"
}
}
],
"responses": {
"200": {
"description": "Successful operation",
"schema": {
"$ref": "#/definitions/NewPetResponse"
},
"headers": {
"Access-Control-Allow-Origin": {
"type": "string",
"description": "URI that may access the resource"
}
}
}
},
"x-amazon-apigateway-integration": {
"responses": {
"default": {
"statusCode": "200",
"responseParameters": {
"method.response.header.Access-Control-Allow-Origin": "'*'"
}
}
},
"uri": "http://petstore-demo-endpoint.execute-api.com/petstore/pets",
"passthroughBehavior": "when_no_match",
"httpMethod": "POST",
"type": "http"
}
},
"options": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Successful operation",
"schema": {
"$ref": "#/definitions/Empty"
},
"headers": {
"Access-Control-Allow-Origin": {
"type": "string",
"description": "URI that may access the resource"
},
"Access-Control-Allow-Methods": {
"type": "string",
"description": "Method or methods allowed when accessing the resource"
},
"Access-Control-Allow-Headers": {
"type": "string",
"description": "Used in response to a preflight request to indicate which HTTP headers can be used when making the request."
}
}
}
},
"x-amazon-apigateway-integration": {
"responses": {
"default": {
"statusCode": "200",
"responseParameters": {
"method.response.header.Access-Control-Allow-Methods": "'POST,GET,OPTIONS'",
"method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
"method.response.header.Access-Control-Allow-Origin": "'*'"
}
}
},
"passthroughBehavior": "when_no_match",
"requestTemplates": {
"application/json": "{\"statusCode\": 200}"
},
"type": "mock"
}
}
},
"/pets/{petId}": {
"get": {
"tags": [
"pets"
],
"summary": "Info for a specific pet",
"operationId": "GetPet",
"produces": [
"application/json"
],
"parameters": [
{
"name": "petId",
"in": "path",
"description": "The id of the pet to retrieve",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "Successful operation",
"schema": {
"$ref": "#/definitions/Pet"
},
"headers": {
"Access-Control-Allow-Origin": {
"type": "string",
"description": "URI that may access the resource"
}
}
}
},
"x-amazon-apigateway-integration": {
"responses": {
"default": {
"statusCode": "200",
"responseParameters": {
"method.response.header.Access-Control-Allow-Origin": "'*'"
}
}
},
"requestParameters": {
"integration.request.path.petId": "method.request.path.petId"
},
"uri": "http://petstore-demo-endpoint.execute-api.com/petstore/pets/{petId}",
"passthroughBehavior": "when_no_match",
"httpMethod": "GET",
"type": "http"
}
},
"options": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"name": "petId",
"in": "path",
"description": "The id of the pet to retrieve",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "Successful operation",
"schema": {
"$ref": "#/definitions/Empty"
},
"headers": {
"Access-Control-Allow-Origin": {
"type": "string",
"description": "URI that may access the resource"
},
"Access-Control-Allow-Methods": {
"type": "string",
"description": "Method or methods allowed when accessing the resource"
},
"Access-Control-Allow-Headers": {
"type": "string",
"description": "Used in response to a preflight request to indicate which HTTP headers can be used when making the request."
}
}
}
},
"x-amazon-apigateway-integration": {
"responses": {
"default": {
"statusCode": "200",
"responseParameters": {
"method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'",
"method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
"method.response.header.Access-Control-Allow-Origin": "'*'"
}
}
},
"passthroughBehavior": "when_no_match",
"requestTemplates": {
"application/json": "{\"statusCode\": 200}"
},
"type": "mock"
}
}
}
},
"definitions": {
"Pets": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
},
"Empty": {
"type": "object"
},
"NewPetResponse": {
"type": "object",
"properties": {
"pet": {
"$ref": "#/definitions/Pet"
},
"message": {
"type": "string"
}
}
},
"Pet": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string"
},
"price": {
"type": "number"
}
}
},
"NewPet": {
"type": "object",
"properties": {
"type": {
"$ref": "#/definitions/PetType"
},
"price": {
"type": "number"
}
}
},
"PetType": {
"type": "string",
"enum": [
"dog",
"cat",
"fish",
"bird",
"gecko"
]
}
},
"x-amazon-apigateway-documentation": {
"version": "v2.1",
"createdDate": "2016-11-17T07:03:59Z",
"documentationParts": [
{
"location": {
"type": "API"
},
"properties": {
"info": {
"description": "Your first API with Amazon API Gateway. This is a sample API that integrates via HTTP with our demo Pet Store endpoints"
}
}
},
{
"location": {
"type": "METHOD",
"method": "GET"
},
"properties": {
"tags": [
"pets"
],
"description": "PetStore HTML web page containing API usage information"
}
},
{
"location": {
"type": "METHOD",
"path": "/pets/{petId}",
"method": "GET"
},
"properties": {
"tags": [
"pets"
],
"summary": "Info for a specific pet"
}
},
{
"location": {
"type": "METHOD",
"path": "/pets",
"method": "GET"
},
"properties": {
"tags": [
"pets"
],
"summary": "List all pets"
}
},
{
"location": {
"type": "METHOD",
"path": "/pets",
"method": "POST"
},
"properties": {
"tags": [
"pets"
],
"summary": "Create a pet"
}
},
{
"location": {
"type": "PATH_PARAMETER",
"path": "/pets/{petId}",
"method": "*",
"name": "petId"
},
"properties": {
"description": "The id of the pet to retrieve"
}
},
{
"location": {
"type": "QUERY_PARAMETER",
"path": "/pets",
"method": "GET",
"name": "page"
},
"properties": {
"description": "Page number of results to return."
}
},
{
"location": {
"type": "QUERY_PARAMETER",
"path": "/pets",
"method": "GET",
"name": "type"
},
"properties": {
"description": "The type of pet to retrieve"
}
},
{
"location": {
"type": "REQUEST_BODY",
"path": "/pets",
"method": "POST"
},
"properties": {
"description": "Pet object that needs to be added to the store"
}
},
{
"location": {
"type": "RESPONSE",
"method": "*",
"statusCode": "200"
},
"properties": {
"description": "Successful operation"
}
},
{
"location": {
"type": "RESPONSE_HEADER",
"method": "OPTIONS",
"statusCode": "200",
"name": "Access-Control-Allow-Headers"
},
"properties": {
"description": "Used in response to a preflight request to indicate which HTTP headers can be used when making the request."
}
},
{
"location": {
"type": "RESPONSE_HEADER",
"method": "OPTIONS",
"statusCode": "200",
"name": "Access-Control-Allow-Methods"
},
"properties": {
"description": "Method or methods allowed when accessing the resource"
}
},
{
"location": {
"type": "RESPONSE_HEADER",
"method": "*",
"statusCode": "200",
"name": "Access-Control-Allow-Origin"
},
"properties": {
"description": "URI that may access the resource"
}
},
{
"location": {
"type": "RESPONSE_HEADER",
"method": "GET",
"statusCode": "200",
"name": "Content-Type"
},
"properties": {
"description": "Media type of request"
}
}
]
}
}

Angularjs $http is unable to get data from Asp.net webapi 4

I am trying to build an application with Asp.net web api and Angularjs
I am trying to get data from API but I am getting a null error as a result.
Asp.net web api code
[RoutePrefix("api/user")]
public class UserController : ApiController
{
[Route("login")]
[HttpGet]
public HttpResponseMessage login(string userId, string password)
{
...code to fetch data
return Request.CreateResponse(HttpStatusCode.OK, result);
}
web config
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var formatters = GlobalConfiguration.Configuration.Formatters;
formatters.Remove(formatters.XmlFormatter);
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
}
Angular Js Code
this.get = function (url, headers = {}) {
/// creating a defer
var def = $q.defer();
$http({
url: url,
dataType: 'json',
method: 'GET',
data: '',
headers: headers
}).success(function (data) {
def.resolve(data);
}).error(function (error) {
def.reject(error);
});
return def.promise;
};
Result
When I am trying to get the result by hitting the API URl I am getting error null
If I am opening the url in web browser then it is returning the JSON
Network Log
{
"log": {
"version": "1.2",
"creator": {
"name": "WebInspector",
"version": "537.36"
},
"pages": [],
"entries": [
{
"startedDateTime": "2016-06-02T16:27:59.550Z",
"time": 25.981999933719635,
"request": {
"method": "GET",
"url": "http://localhost:62158/api/user/login?userId=undefined&password=abc",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "Origin",
"value": "http://localhost:8000"
},
{
"name": "Accept-Encoding",
"value": "gzip, deflate, sdch"
},
{
"name": "Host",
"value": "localhost:62158"
},
{
"name": "Accept-Language",
"value": "en-US,en;q=0.8,hi;q=0.6,und;q=0.4"
},
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36"
},
{
"name": "Accept",
"value": "application/json, text/plain, */*"
},
{
"name": "Referer",
"value": "http://localhost:8000/"
},
{
"name": "Connection",
"value": "keep-alive"
}
],
"queryString": [
{
"name": "userId",
"value": "undefined"
},
{
"name": "password",
"value": "abc"
}
],
"cookies": [],
"headersSize": 429,
"bodySize": 0
},
"response": {
"status": 200,
"statusText": "OK",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "Pragma",
"value": "no-cache"
},
{
"name": "Date",
"value": "Thu, 02 Jun 2016 16:27:59 GMT"
},
{
"name": "Server",
"value": "Microsoft-IIS/8.0"
},
{
"name": "X-AspNet-Version",
"value": "4.0.30319"
},
{
"name": "X-Powered-By",
"value": "ASP.NET"
},
{
"name": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"name": "Cache-Control",
"value": "no-cache"
},
{
"name": "X-SourceFiles",
"value": "=?UTF-8?B?QzpcVXNlcnNca2lyXERlc2t0b3BcRSBEcml2ZVxXb3JrIExpdmVcTml0aW4gS0sgU29mdHdhcmVcVmlkZW9MaWJyYXJ5XHByb2plY3RcVmlkZW9MSWJyYXJ5XFZpZGVvTElicmFyeVxhcGlcdXNlclxsb2dpbg==?="
},
{
"name": "Content-Length",
"value": "46"
},
{
"name": "Expires",
"value": "-1"
}
],
"cookies": [],
"content": {
"size": 0,
"mimeType": "application/json",
"compression": 447,
"text": ""
},
"redirectURL": "",
"headersSize": 447,
"bodySize": -447,
"_transferSize": 0,
"_error": ""
},
"cache": {},
"timings": {
"blocked": 2.24999990314245,
"dns": -1,
"connect": -1,
"send": 0.19500008784235012,
"wait": 22.8659999556839,
"receive": 0.6709999870509336,
"ssl": -1
},
"serverIPAddress": "[::1]",
"connection": "15008"
}
]
}
}
Same Hit in browser giving result
As KKKKKKKK and rick have already pointed out you don't need to create another promise as $http.get will already return one. You should also make use of then as opposed to succcess/failure
So what you want should look like this:
function getData() {
return $http.get('path-to-api/api.json').then(
function success(result) {
// Do stuff with it
return result.data;
},
function failure(err) {
return err;
});
}
Note this places the call in a service and returns the function in an object from that service.
EDIT
Because the comments concates URLS I'll add this as an edit:
So the url you're hitting on the angular side is:
http://localhost:62158/api/user/login?userId=undefined&password=abc.json
or is http://localhost:62158/api/user/login?userId=undefined&password=abc
#Katana24 I do not know how to thank you but you made me get this answer... thanks a lot.
Reason
Asp.net web api does not allow cross origin request until and unless you add Access-Control-Allow-Origin in web.config file. I made it * so from any origin the APIes is accessible.
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>

Categories

Resources