Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在基于IP的URL上设置获取(用于POST API)中的cookie_Javascript_Rest_Cookies_Reactjs_Fetch - Fatal编程技术网

Javascript 如何在基于IP的URL上设置获取(用于POST API)中的cookie

Javascript 如何在基于IP的URL上设置获取(用于POST API)中的cookie,javascript,rest,cookies,reactjs,fetch,Javascript,Rest,Cookies,Reactjs,Fetch,我在reactJS中使用fetchforrestapi,并使用 credentials: "include" 但它不适用于(**基于IP的url)。这是我的响应头配置 Access-Control-Allow-Credentials:true Access-Control-Allow-Headers:X-Requested-With, X-CSRF-Token, X-Auth-Token, Content-Type, Origin, Authorization, Accept, Client

我在reactJS中使用fetchforrestapi,并使用

 credentials: "include"
但它不适用于(**基于IP的url)。这是我的响应头配置

Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:X-Requested-With, X-CSRF-Token, X-Auth-Token, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding
Access-Control-Allow-Methods:POST, GET
Access-Control-Allow-Origin:http://localhost:8080
Content-Length:93
Content-Type:application/json; charset=UTF-8
Date:Sun, 24 Jul 2016 20:29:48 GMT
**当我做POST请求时,我的本地ip是192.168.1.4,cookie没有发送到服务器

 fetch('http://192.168.1.4:9000/test', {
        credentials: "include",
        method: 'post',
        mode: 'cors',   
        headers: {
            'Accept': 'application/json'
        },
        body: JSON.stringify({
           "username":"abd",
           "passwd":"Changemes1"
        }) 
这里是本地ip的请求头(192.168.1.4)

但是当我使用本地主机而不是我的本地ip(192.168.1.4)时,浏览器发送COOKIE就完美了

 fetch('http://localhost:9000/test', {
            credentials: "include",
            method: 'post',
            mode: 'cors',   
            headers: {
                'Accept': 'application/json'
            },
            body: JSON.stringify({
               "username":"abd",
               "passwd":"Changemes1"
            })
请参见此处(请求头,Cookie:Token=johndoepresent)-


基于IP的url有什么问题请告诉我。

您是否为基于IP的url设置过cookie?是的,我为两个url都设置了cookie您是否为基于IP的url设置过cookie?是的,我为两个url都设置了cookie
 fetch('http://localhost:9000/test', {
            credentials: "include",
            method: 'post',
            mode: 'cors',   
            headers: {
                'Accept': 'application/json'
            },
            body: JSON.stringify({
               "username":"abd",
               "passwd":"Changemes1"
            })
accept:application/json
Accept-Encoding:gzip, deflate
Accept-Language:en-GB,en;q=0.8,en-US;q=0.6,hi;q=0.4,ru;q=0.2
Cache-Control:no-cache
Connection:keep-alive
Content-Length:115
content-type:text/plain;charset=UTF-8
Cookie:Token=John Doe
Host:localhost:9000
Origin:http://localhost:8080
Pragma:no-cache
Referer:http://localhost:8080/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36