我应该给什么域这个cookie? [英] What domain should I give this cookie?

查看:117
本文介绍了我应该给什么域这个cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从C#应用程序调用Web服务,与会话ID
。 为了做到这一点,我需要设置域报头中的cookie。

I'm trying to call a web service from a c# application, with sessionID.
In order to do this I need to set the "Domain" header in a cookie.

在提琴手它看起来像 - ASP.NET_SessionId = izdtd4tbzczsa3nlt5ujrbf5(无域在cookie中指定)。

In Fiddler it looks like - "ASP.NET_SessionId=izdtd4tbzczsa3nlt5ujrbf5" (no domain is specified in the cookie).

Web服务是 - HTTP:// [某些IP放在这里]:8989 / MyAPI.asmx。

The web service is at - "http://[some ip goes here]:8989/MyAPI.asmx".

我已经试过:
HTTP:// [IP],
HTTP:// [IP]:8989,
HTTP:// [IP]:8989 / MyAPI.asmx

I've tried:
http://[ip] ,
http://[ip]:8989 ,
http://[ip]:8989/MyAPI.asmx

所有这些原因运行时错误的。

All of these cause runtime error.

我也尝试了IP单独(即100.10.10.10),而不会导致运行时错误,并设置cookie,但该cookie将被永远不会发送当我调用Web方法。

I've also tried the ip alone (i.e. 100.10.10.10) , which doesn't cause a runtime error, and sets the cookie, but the cookie is never sent when I invoke a web method.

下面是我的code设置的域:

Here's my code for setting the domain:

if (!string.IsNullOrEmpty(currentSessionID))
{
   req.CookieContainer=new CookieContainer();
   Cookie cookie = new Cookie("ASP.NET_SessionId", currentSessionID);
   cookie.Domain = GetCookieUrl();  //<- What should this be?
   req.CookieContainer.Add(cookie);
}

那么应该怎么领域是什么?

So what should the domain be?

感谢。

推荐答案

该Cookie未发送的原因是该请求的内容长度应该设置的添加饼干,而不是之前。< BR> 域名是IP孤单。

The reason the cookie was not sent is that the request's content length should be set after adding the cookie, and not before.
The domain is the ip alone.

这篇关于我应该给什么域这个cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆