android http basic,Error “HTTP/1.1 401 Unauthorized” with basic authentication in android - EWS 2010...

I refer to this link to request to the server. The problem is sometime (not always, about 20% - 30%, means sometime I can get successful response), I got the 401 error and server response basic authorization challenge expected, but not found.

Here is my code: HttpRequestInterceptor preemptiveAuth = new HttpRequestInterceptor() { public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context .getAttribute(ClientContext.TARGET_AUTH_STATE); CredentialsProvider credsProvider = (CredentialsProvider) context .getAttribute(ClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context .getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (authState.getAuthScheme() == null) { AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); Credentials creds = credsProvider.getCredentials(authScope); if (creds != null) { authState.setAuthScheme(new BasicScheme()); authState.setCredentials(creds); } } } };

Here is my authentication: HttpPost httpPost = new HttpPost(SERVER_AUTH_URL); httpPost.setHeader("Content-type", "text/xml; charset=utf-8"); httpPost.setHeader("Keep-Alive", "300"); httpPost.setHeader("Connection", "Keep-Alive"); StringEntity se = new StringEntity(myRequest, "UTF-8"); httpPost.setEntity(se); se.setContentType("text/xml"); se.setContentEncoding("gzip,deflate"); //add preemptiveAuth client.addRequestInterceptor(preemptiveAuth, 0); //Set the proxy ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner( client.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault()); client.setRoutePlanner(routePlanner); ListauthPrefs = new ArrayList(); authPrefs.add(AuthPolicy.BASIC); authPrefs.add(AuthPolicy.NTLM); authPrefs.add(AuthPolicy.DIGEST); client.getParams().setParameter("http.auth.scheme-priority", authPrefs); CredentialsProvider credProvider = new BasicCredentialsProvider(); // client.getParams().setParameter("http.auth.scheme-priority", // authPrefs); credProvider.setCredentials(AuthScope.ANY, new NTCredentials(getUsername(), getPassword(), "", getDomain())); Log.d(TAG, "repair excute"); client.setCredentialsProvider(credProvider); HttpResponse response = client.execute(httpPost); Log.d(TAG, "has excute");

From the comment code, you can see I tried many ways, but the error wasn't disappear. Here is logcat say: 05-02 10:28:21.724: D/dalvikvm(1169): GC_FOR_MALLOC freed 11259 objects / 457352 bytes in 43ms 05-02 10:28:22.384: D/MainActivity(1169): repair excute 05-02 10:28:22.744: D/dalvikvm(1169): GC_FOR_MALLOC freed 11481 objects / 447264 bytes in 67ms 05-02 10:28:22.894: D/dalvikvm(1169): GC_FOR_MALLOC freed 1078 objects / 83928 bytes in 76ms 05-02 10:28:22.894: I/dalvikvm-heap(1169): Grow heap (frag case) to 3.833MB for 87396-byte allocation 05-02 10:28:23.034: D/dalvikvm(1169): GC_FOR_MALLOC freed 58 objects / 3336 bytes in 143ms 05-02 10:28:23.124: W/DefaultRequestDirector(1169): Authentication error: basic authorization challenge expected, but not found 05-02 10:28:23.124: D/MainActivity(1169): has excute 05-02 10:28:23.124: E/MainActivity(1169): response error: HTTP/1.1 401 Unauthorized

So, please tell me where is my problem. Thanks in advance.

Update: the target server is Exchange Web Service 2010. For some reason, I don't want to use EWS API, I made my own xml request to connect to the server (this xml request works properly).

And here is the response header from server When request failed: Server Microsoft-IIS/7.5 WWW-Authenticate Negotiate WWW-Authenticate NTLM X-Powered-By ASP.NET Date Fri, 25 May 2012 03:47:57 GMT Content-Length 0

When request success the first time: Cache-Control private Transfer-Encoding chunked Content-Type text/xml; charset=utf-8 Server Microsoft-IIS/7.5 Set-Cookie exchangecookie=1d9d9b1d21064035ad375c8aecde2168; expires=Sat, 25-May-2013 04:00:46 GMT; path=/; HttpOnly X-AspNet-Version 2.0.50727 X-Powered-By ASP.NET Date Fri, 25 May 2012 04:00:45 GMT

and the second time: Cache-Control private Transfer-Encoding chunked Content-Type text/xml; charset=utf-8 Server Microsoft-IIS/7.5 X-EwsPerformanceData RpcC=4;RpcL=0;LdapC=0;LdapL=0; X-AspNet-Version 2.0.50727 X-Powered-By ASP.NET Date Fri, 25 May 2012 04:00:47 GMT

The cookie is my problem, isn't it?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ce-side assert triggered是由于代码中出现了索引越界导致的错误。这个错误是CUDA报错,具体原因可能是代码中的某个索引超出了合法范围。然而,根据引用\[2\]所述,报错位置的代码并不一定是错误的根本位置,因此需要进一步分析。根据引用\[3\]的问题分析,可能是由于维度范围溢出导致的CUDA错误。为了解决这个问题,可以检查代码中的索引操作,确保索引值在合法范围内。此外,还可以尝试使用调试工具来定位错误的具体位置,并查看相关的报错信息以获取更多的线索。 #### 引用[.reference_title] - *1* *2* [RuntimeError: CUDA error: device-side assert triggered Pytorch框架代码运行错误解决方案(亲测有效!...](https://blog.csdn.net/weixin_42112050/article/details/120455407)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [「Bug」问题分析 RuntimeError: CUDA error: device-side assert triggered](https://blog.csdn.net/ViatorSun/article/details/125207465)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值