如何在 POST 方法中格式化 Cookie 以匹配 iOS
How to format Cookie in POST method to match iOS
尝试将此 iOS 代码复制到我的 Android httpUrlConnection post 方法,下面是 objc:
NSDictionary *properties = @{
NSHTTPCookiePath: @"/",
NSHTTPCookieDomain: [request.URL host],
NSHTTPCookieName: @"session_state",
NSHTTPCookieValue: state,
};
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:properties];
NSDictionary *cookieHeaders = [NSHTTPCookie requestHeaderFieldsWithCookies:@[cookie]];
这是我在 Android 应用程序中设置的内容:
conn.setRequestProperty("Cookie", "session_state=" + state);
我的问题是如何正确匹配这两个,以便我的 Android cookie 等同于 iOS 示例
为了回答我自己的问题,我使用了 httpClient 和 httpPost 而不是 httpUrlConnection,它看起来像这样:
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Cookie", "session_state=" + state);
尝试将此 iOS 代码复制到我的 Android httpUrlConnection post 方法,下面是 objc:
NSDictionary *properties = @{
NSHTTPCookiePath: @"/",
NSHTTPCookieDomain: [request.URL host],
NSHTTPCookieName: @"session_state",
NSHTTPCookieValue: state,
};
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:properties];
NSDictionary *cookieHeaders = [NSHTTPCookie requestHeaderFieldsWithCookies:@[cookie]];
这是我在 Android 应用程序中设置的内容:
conn.setRequestProperty("Cookie", "session_state=" + state);
我的问题是如何正确匹配这两个,以便我的 Android cookie 等同于 iOS 示例
为了回答我自己的问题,我使用了 httpClient 和 httpPost 而不是 httpUrlConnection,它看起来像这样:
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Cookie", "session_state=" + state);