Android XcapClinet 二

来源:互联网 发布:sql报表编辑器 编辑:程序博客网 时间:2024/04/30 13:33

Android XcapClinet 二、android客户端编写

转载注明出处:http://blog.csdn.net/gremorse/article/details/11737143

需要借助工具:wireshark

过滤http

以put方法为例,使用Xcapclient测试put方法时抓包得到的结果是

xcapclient                              openxcap

       |                 PUT                     \ |

       |/                 401                       |

       |                 PUT                     \ |

       |/                 200                       |

过程很迂回,出现的关键字字眼为WWW-Authenticate,参照RFC2617

public static String sendPut(String url, Map<String, String> headers,String entityString, String sipName, String sipPwd)throws ClientProtocolException, IOException,MalformedChallengeException, AuthenticationException {DefaultHttpClient httpClient = (DefaultHttpClient) getHttpClient();HttpPut httpPut = new HttpPut(url);String response = "";if (headers != null) {httpPut.setHeaders(convertHead(headers));}if (entityString != null)httpPut.setEntity(new StringEntity(entityString));HttpResponse httpResponse = httpClient.execute(httpPut);if (httpResponse.getStatusLine().getStatusCode() == 401) {DigestScheme md5Auth = new DigestScheme();// 提取鉴权元素Header challenge = httpResponse.getHeaders("WWW-Authenticate")[0];md5Auth.processChallenge(challenge);Header solution = md5Auth.authenticate(new UsernamePasswordCredentials(sipName, sipPwd),new BasicHttpRequest(HttpPut.METHOD_NAME, new URL(url).getPath()));Map<String, String> tempHeaders = new HashMap<String, String>();tempHeaders = headers;tempHeaders.put(solution.getName(), solution.getValue());response = sendPut(url, tempHeaders, entityString, sipName, sipPwd);} else {response += httpResponse.getStatusLine() + "\r\n";for (Header tempHeader : httpResponse.getAllHeaders()) {response += tempHeader.getName() + ":";response += tempHeader.getValue() + "\r\n";}response += EntityUtils.toString(httpResponse.getEntity());}httpPut.abort();return response;}
主要还是在
if (httpResponse.getStatusLine().getStatusCode() == 401)



原创粉丝点击