java使用httpclient向百度的收录入口提交URL报 403错误

package com.galaxy.promotion.baidu;

import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class Test {
public static void main(String[] args) throws HttpException, IOException {
HttpClient httpclient = new HttpClient();
// 创建post方法实例
PostMethod postMethod = new PostMethod("http://zhanzhang.baidu.com/linksubmit/urlsubmit");

    // 填入各个表单域的值
    NameValuePair[] data = { new NameValuePair("url", "www.example.com") };

    // 将表单的值放入到post方法中
    postMethod.setRequestBody(data);
    // 执行post方法
    int statusCode = httpclient.executeMethod(postMethod);
    System.out.println(statusCode);
    System.out.println(postMethod.getStatusLine());
}

}

1个回答

是不是依赖一些请求头

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
java httpClient 发送httpGet 请求 特殊字符

java httpClient 发送httpGet 请求,请求url串中有特殊字符,如果不进行转义,如何发送呀??(服务端不是我的,如果转义了服务端验证不过) 补充:在浏览器地址栏直接复制url(带特殊字符),返回结果正确。

使用HttpClient进行登录验证

<div class="post-text" itemprop="text"> <p>I am trying to send a POST request to a php file and when the user is asked for login information, if wrong, it prints the json message from the php file and if right, it allows user to login. However, my application crashes, giving a NetworkOnThreadMainException pointing errors to three lines.</p> <pre><code> HttpResponse response=httpClient.execute(httpPost); public class LoginActivity extends ActionBarActivity { login(); </code></pre> <p>So how can i make this possible? This is some part of the code I have written:</p> <pre><code>public class LoginActivity extends ActionBarActivity { EditText et, et2; ImageButton ib5; String name,pwd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); et = (EditText) findViewById(R.id.editText); et2 = (EditText) findViewById(R.id.editText2); ib5 = (ImageButton) findViewById(R.id.imageButton5); name=et.getText().toString(); pwd=et2.getText().toString(); final LoginActivity loginActivity=null; ib5.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //login(); new DownloadFilesTask(loginActivity,name,pwd).doInBackground(); } }); } public void login() { new LoginTask(this, et.getText().toString(), et2.getText().toString()); } private class LoginTask { public LoginTask(LoginActivity loginActivity, String name, String pwd) { } } void navigatetoMainActivity() { Intent homeIntent = new Intent(getApplicationContext(), MainActivity.class); homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(homeIntent); } void InvalidToast(){ Toast.makeText(getApplicationContext(), "Please enter valid name and password", Toast.LENGTH_LONG).show(); } void EmptyToast(){ Toast.makeText(getApplicationContext(), "Please fill the form, don't leave any field blank", Toast.LENGTH_LONG).show(); } } </code></pre> <p>DownloadFilesTask.java</p> <pre><code>public class DownloadFilesTask extends AsyncTask&lt;String, String, String&gt; { private String name, pwd; private LoginActivity loginActivity; public DownloadFilesTask(LoginActivity loginActivity,String name, String pwd){ this.loginActivity=loginActivity; this.name=name; this.pwd=pwd; } @Override protected String doInBackground(String... strings) { HttpClient httpClient=new DefaultHttpClient(); HttpPost httpPost=new HttpPost("login.php"); List&lt;NameValuePair&gt; nameValuePairs=new ArrayList&lt;NameValuePair&gt;(2); String result=null; nameValuePairs.add(new BasicNameValuePair("name", name)); nameValuePairs.add(new BasicNameValuePair("password", pwd)); try { httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } HttpResponse response= null; try { response = httpClient.execute(httpPost); //error is given here } catch (IOException e) { e.printStackTrace(); } HttpEntity entity=response.getEntity(); InputStream instream= null; try { instream = entity.getContent(); } catch (IOException e) { e.printStackTrace(); } result=convertStreamToString(instream); try { instream.close(); } catch (IOException e) { e.printStackTrace(); } if (Utility.isNotNull(name) &amp;&amp; Utility.isNotNull(pwd)) { RequestParams params = new RequestParams(); if (Utility.validate(name, pwd)) { params.put("username", name); params.put("password", pwd); onPostExecute(); } else { loginActivity.InvalidToast(); } } else { loginActivity.EmptyToast(); } return result; } private String convertStreamToString(InputStream instream) { BufferedReader reader=new BufferedReader(new InputStreamReader(instream)); StringBuilder sb=new StringBuilder(); String line=null; try { while ((line=reader.readLine())!=null){ sb.append(line + " "); } } catch (IOException e) { e.printStackTrace(); }finally{ try { instream.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } protected void onPostExecute(){ loginActivity.navigatetoMainActivity(); } private static class Utility { static Pattern pattern; static Matcher matcher; static Pattern pattern1; static Matcher matcher1; static String NAME_PATTERN="SuperBoise"; static String PWD_PATTERN="qwerty"; public static boolean validate(String name,String pwd){ pattern=Pattern.compile(NAME_PATTERN); pattern1=Pattern.compile(PWD_PATTERN); matcher=pattern.matcher(name); matcher1=pattern1.matcher(pwd); return matcher.matches()&amp;&amp; matcher1.matches(); } public static boolean isNotNull(String name) { return name!=null &amp;&amp; name.trim().length()&gt;0 ? true: false; } } } </code></pre> </div>

java实现httpclient上传文件和普通参数到servlet

哪位能推荐一个好的方法,实现httpclient上传文件和普通参数到servlet,post方法,servlet端是普通web项目,不能用spring相关方法。自测使用的MultipartEntityBuilder,但是servlet接收不到上传的参数,在线急等

java HttpClient 请求乱码

java HttpClient 4.3.6的jar包 为什么我get post 请求中文乱码 还有怎么请求的时候怎么带参数,我这样写有什么问题没有,现在的情况就是乱码 public static void get() { try { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpGet httpget = new HttpGet("http://api.a.7xz.com/v140/ceshi"); httpget.addHeader(new BasicHeader("npi", "3")); // httpget.addHeader("", ""); CloseableHttpResponse httpReponse = httpClient.execute(httpget); try { System.out.println(httpReponse.getStatusLine()); HttpEntity entity = httpReponse.getEntity(); System.out.println(EntityUtils.toString(entity)); } finally { httpReponse.close(); } } catch (Exception e) { e.printStackTrace(); } } public static void post() { try { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost("http://api.a.7xz.com/v140/ceshi"); List<BasicNameValuePair> Listnvps = new ArrayList(); Listnvps.add(new BasicNameValuePair("npi", "3")); httpPost.setEntity(new UrlEncodedFormEntity(Listnvps, "UTF-8")); CloseableHttpResponse httppHttpResponse2 = httpClient .execute(httpPost); try { System.out.println(httppHttpResponse2.getStatusLine()); System.out.println(EntityUtils.toString(httppHttpResponse2 .getEntity())); } finally { httppHttpResponse2.close(); } httpClient.close(); } catch (Exception e) { e.printStackTrace(); } }

java httpclient get请求拼接json数组到请求url后面

如何将一个json数组拼接到http Get请求的url后面? 我是在后台程序中模拟请求,用httpClient实现。有如下几种尝试: 1.http://localhost:8080/test/name=["123","456"] HttpGet httpget = new HttpGet(url); 处理报错 url格式不规范 2.将name=value 的vaule数组值进行urlEncode,从服务端用 String[] name = request.getParameterValues("name"); 取出来的是“["123","456"]”一个元素的数组 请大神们帮忙解答一下 如何将一个数组添加到get请求的url后面

java中使用httpclient post请求时报空指针异常

``` maven : <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.2</version> </dependency> ``` 相关代码: ``` HttpPost httppost = new HttpPost("http://localadmin/xxxxx"); List<NameValuePair> list = new ArrayList<NameValuePair>(); list.add(new BasicNameValuePair("identityNum","xxxxx")); list.add(new BasicNameValuePair("channel","YT")); list.add(new BasicNameValuePair("userId","78652109462")); list.add(new BasicNameValuePair("userName","xxxxx")); list.add(new BasicNameValuePair("realName","xxxxx")); UrlEncodedFormEntity entity ; try { entity = new UrlEncodedFormEntity(list, "utf-8"); httppost.setEntity(entity); ...... ``` 调试发现: ``` 在 super(URLEncodedUtils.format(parameters, charset != null?charset:HTTP.DEF_CONTENT_CHARSET.name()), ContentType.create("application/x-www-form-urlencoded", charset));处报 Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.apache.http.client.entity.UrlEncodedFormEntity.toString() ``` 有同学遇到过吗?

java的httpclient能实现linux中的curl -u命令吗?

java的httpclient能实现linux中的curl -u命令吗?如何实现

JAVA利用HttpClient进行POST请求然后我老是报30602,请求参数错误,求大神帮我解决

这是我我copy别人代码的源代码路径文档http://blog.csdn.net/rongyongfeikai2/article/details/41659353/ 这是我的myeclipse截图![![![图片说明](https://img-ask.csdn.net/upload/201612/15/1481798455_807748.png)图片说明](https://img-ask.csdn.net/upload/201612/15/1481798443_229446.png)图片说明](https://img-ask.csdn.net/upload/201612/15/1481798435_775949.png)

关于JAVA HttpClient链接超时问题

在项目中运用到了httpclient进行发送和接受请求,不知道为什么再走断点进行一步一步的查看代码的时候 走到这一步会出现链接超时,而如果不走断点却没有问题。 时间设置我设置成了30000000毫秒,走断点一直没有反应,等待遥遥无期,设置成30秒缺超时,请求大神帮忙解答疑问,是我eclipse的问题还是项目代码的问题?

关于java Httpclient post 提交JSon数据的问题

我查出数据库的数据 推送给安卓解析, 由于安卓的接口没有做好,我自己做了个 servlst 进行解析。但是不知道怎么拿值! 这是 推送数据的方法! public static String doPost(String url,JSONArray json){ String result=null; DefaultHttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); JSONObject response = null; try { StringEntity s = new StringEntity(json.toString()); s.setContentEncoding("UTF-8"); s.setContentType("application/json");//发送json数据需要设置contentType post.setEntity(s); HttpResponse res = client.execute(post); if(res.getStatusLine().getStatusCode() == HttpStatus.SC_OK){ HttpEntity entity = res.getEntity(); result = EntityUtils.toString(res.getEntity());// 返回json格式: // response = JSONObject.fromObject(result); } } catch (Exception e) { throw new RuntimeException(e); } return result; } 一下是 servlst 解析的方法 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("POST请求方式"); response.setContentType("text/html"); PrintWriter out = response.getWriter(); //String param=request.getParameter(""); //接收数据 out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the POST 200 method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); }

使用HttpClient时遇到的 java.net.SocketException: Socket closed异常

public static Object[] callService(String wsUrl, String method, Object... arg) { logger.info("---enter callService---"); DynamicClientFactory dcf = DynamicClientFactory.newInstance(); Client client = dcf.createClient(wsUrl); HTTPConduit conduit = (HTTPConduit) client.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); long timeout = 10 * 60 * 1000;// policy.setConnectionTimeout(timeout); policy.setReceiveTimeout(timeout); conduit.setClient(policy); Object[] res = null; try { res = client.invoke(method, arg); } catch (Exception e) { e.printStackTrace(); logger.error("send msg failed" + e.getMessage()); } return res ; } [2018-12-20 17:37:16,021]-INFO (SoapClient.java:36)|---enter callService--- [2018-12-20 17:37:18,042]-INFO (JAXBUtils.java:719)|Created classes: com.yggdrasill.work.flow.common.web.ObjectFactory, com.yggdrasill.work.flow.common.web.ReqMainAccount, com.yggdrasill.work.flow.common.web.ReqMainAccountResponse [2018-12-20 17:37:19,893]-WARN (LogUtils.java:371)|Interceptor for {http://web.common.flow.work.yggdrasill.com}PartenerInfoImpService#{http://web.common.flow.work.yggdrasill.com}reqMainAccount has thrown exception, unwinding now org.apache.cxf.interceptor.Fault: Could not send Message. at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263) at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:519) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:449) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:352) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:304) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:324) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:310) at com.boco.mis.cxf.CXFServices.SoapClient.callService(SoapClient.java:41) at com.boco.mis.account.action.AccountAction.goSmp(AccountAction.java:135) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254) at com.boco.mss.plat.interceptor.ErrorInterceptor.intercept(ErrorInterceptor.java:25) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.boco.common.base.interceptor.LoginInterceptor.doFilter(LoginInterceptor.java:112) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:615) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:662) Caused by: java.net.SocketException: SocketException invoking http://10.131.120.99:8088/workflow/ws/PartnerService: Socket Closed at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.mapException(HTTPConduit.java:1422) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1407) at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:640) at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62) ... 84 more Caused by: java.net.SocketException: Socket Closed at java.net.PlainSocketImpl.getOption(PlainSocketImpl.java:286) at java.net.Socket.getSoTimeout(Socket.java:1032) at sun.net.www.http.HttpClient.available(HttpClient.java:356) at sun.net.www.http.HttpClient.New(HttpClient.java:273) at sun.net.www.http.HttpClient.New(HttpClient.java:310) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:987) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:923) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:841) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1031) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleHeadersTrustCaching(HTTPConduit.java:1359) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.onFirstWrite(HTTPConduit.java:1301) at org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:42) at org.apache.cxf.io.AbstractThresholdOutputStream.write(AbstractThresholdOutputStream.java:69) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1379) ... 87 more org.apache.cxf.interceptor.Fault: Could not send Message. at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263) at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:519) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:449) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:352) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:304) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:324) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:310) at com.boco.mis.cxf.CXFServices.SoapClient.callService(SoapClient.java:41) at com.boco.mis.account.action.AccountAction.goSmp(AccountAction.java:135) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254) at com.boco.mss.plat.interceptor.ErrorInterceptor.intercept(ErrorInterceptor.java:25) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.boco.common.base.interceptor.LoginInterceptor.doFilter(LoginInterceptor.java:112) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:615) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:662) Caused by: java.net.SocketException: SocketException invoking http://10.131.120.99:8088/workflow/ws/PartnerService: Socket Closed at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.mapException(HTTPConduit.java:1422) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1407) at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:640) at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62) ... 84 more Caused by: java.net.SocketException: Socket Closed at java.net.PlainSocketImpl.getOption(PlainSocketImpl.java:286) at java.net.Socket.getSoTimeout(Socket.java:1032) at sun.net.www.http.HttpClient.available(HttpClient.java:356) at sun.net.www.http.HttpClient.New(HttpClient.java:273) at sun.net.www.http.HttpClient.New(HttpClient.java:310) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:987) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:923) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:841) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1031) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleHeadersTrustCaching(HTTPConduit.java:1359) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.onFirstWrite(HTTPConduit.java:1301) at org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:42) at org.apache.cxf.io.AbstractThresholdOutputStream.write(AbstractThresholdOutputStream.java:69) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1379) ... 87 more [2018-12-20 17:37:19,900]-ERROR (SoapClient.java:44)|send msg failedCould not send Message.

java关于Httpclient传递token值的用法

是这样的,对方传来一个地址以及一个token值,现在是要获取地址里面数据,但是需要token的验证,如何在java发送请求的同时,验证token值,token值是固定不变

使用httpclient代理ip然后通过百度搜索一个词进入一个页面

就是利用代理ip来模拟百度搜索,然后返回这个页面然后记录!这个可以实现吗?!具体代码是什么啊!? 还有代码的意义是什么?

HttpClient请求POST提示302,而且返回的response中的Localtion是我访问时使用的URL?

HttpClient请求POST提示302,而且返回的response中的Localtion是我访问时使用的URL, 例如:我使用的URL是https://bbs.csdn.net?client_id=10333&user=test, localtion中也是这个https://bbs.csdn.net?client_id=10333&user=test 我试了直接使用curl可以返回json 我的post方法: ```java public static StringBuilder post(String url, Object data, String encoding) { log.info("HttpClient post start => "+url); CloseableHttpResponse response = null; HttpPost httpPost = null; HttpHost httpHost = null; StringBuilder responseEntity = null; String strings = ""; URL _url = new URL(url); httpPost = new HttpPost(url); httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); if(!Stringer.isNullOrEmpty(data)){ log.debug("HttpClient post url => "+url+", data:"+JSON.toJSONString(data)); if (data instanceof Map) { // Map方式传参处理 Map<String,String> params = (Map<String,String>) data; List<NameValuePair> nvps = new ArrayList<NameValuePair>(); if (!Stringer.isNullOrEmpty(data)) { Set<String> keySet = params.keySet(); for (String key : keySet) { nvps.add(new BasicNameValuePair(key, params.get(key))); } } httpPost.setEntity(new UrlEncodedFormEntity(nvps, encoding)); } else if(data instanceof String){ // String方式传参处理 strings = (String)data; strings = Stringer.nullToEmpty(strings); ByteArrayEntity reqEntity = new ByteArrayEntity(strings.getBytes(encoding)); reqEntity.setContentEncoding(encoding); httpPost.setEntity(reqEntity); } } httpPost.setConfig(defaultRequestConfig); httpHost = new HttpHost(_url.getHost(),_url.getPort()); response = httpClient.execute(httpHost,httpPost); if(!Stringer.isNullOrEmpty(response)){ log.info("2--HttpClient response => "+response); log.info("3--HttpClient StatusCode => "+response.getStatusLine().getStatusCode()); /*if (response.getStatusLine().getStatusCode() != 200) { return null; }*/ String locationUrl=response.getLastHeader("location").getValue(); log.info("HttpClient locationUrl => "+locationUrl); log.info("4--HttpClient StatusCode => "+response.getStatusLine().getStatusCode()); if (response.getStatusLine().getStatusCode() == 302) { Header header = response.getFirstHeader("location"); // 跳转的目标地址是在 HTTP-HEAD上 String newuri = header.getValue(); // 这就是跳转后的地址,再向这个地址发出新申请 System.out.println(newuri); httpPost = new HttpPost(newuri); httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); response = httpClient.execute(httpHost,httpPost); int code = response.getStatusLine().getStatusCode(); locationUrl=response.getLastHeader("location").getValue(); log.info("5--HttpClient new Code => "+code); log.info("6--HttpClient locationUrl => "+locationUrl); } responseEntity = new StringBuilder(); responseEntity.append(EntityUtils.toString(response.getEntity(), encoding)); return responseEntity; } return null; } ``` curl命令样例: curl -k -d "client_id=10333&user=test" "https://bbs.csdn.net" 大神们帮忙看看吧

关于HttpClient的问题,如何使用HttpClient重定向?

``` /* * HttpRequestProxy.java * * Created on November 3, 2008, 9:53 AM */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.SimpleHttpConnectionManager; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; public class HttpRequestProxy { // 超时间隔 private static int connectTimeOut = 60000; // 让connectionmanager管理httpclientconnection时是否关闭连接 private static boolean alwaysClose = false; // 返回数据编码格式 private String encoding = "UTF-8"; private final HttpClient client = new HttpClient(); public HttpClient getHttpClient() { return client; } /** * 用法: HttpRequestProxy hrp = new HttpRequestProxy(); * hrp.doRequest("http://www.163.com",null,null,"gbk"); * * @param url * 请求的资源URL * @param postData * POST请求时form表单封装的数据 没有时传null * @param header * request请求时附带的头信息(header) 没有时传null * @param encoding * response返回的信息编码格式 没有时传null * @return response返回的文本数据 * @throws CustomException */ public String doRequest(String url, Map postData, Map header, String encoding) throws Exception { String responseString = null; // 头部请求信息 Header[] headers = null; if (header != null) { Set entrySet = header.entrySet(); int dataLength = entrySet.size(); headers = new Header[dataLength]; int i = 0; for (Iterator itor = entrySet.iterator(); itor.hasNext();) { Map.Entry entry = (Map.Entry) itor.next(); headers[i++] = new Header(entry.getKey().toString(), entry.getValue().toString()); } } // post方式 if (postData != null) { PostMethod postRequest = new PostMethod(url.trim()); if (headers != null) { for (int i = 0; i < headers.length; i++) { postRequest.setRequestHeader(headers[i]); } } Set entrySet = postData.entrySet(); int dataLength = entrySet.size(); NameValuePair[] params = new NameValuePair[dataLength]; int i = 0; for (Iterator itor = entrySet.iterator(); itor.hasNext();) { Map.Entry entry = (Map.Entry) itor.next(); params[i++] = new NameValuePair(entry.getKey().toString(), entry.getValue().toString()); } postRequest.setRequestBody(params); try { responseString = this.executeMethod(postRequest, encoding); } catch (Exception e) { throw e; } finally { postRequest.releaseConnection(); } } return responseString; } private String executeMethod(HttpMethod request, String encoding) throws Exception { String responseContent = null; InputStream responseStream = null; BufferedReader rd = null; try { this.getHttpClient().executeMethod(request); if (encoding != null) { responseStream = request.getResponseBodyAsStream(); rd = new BufferedReader(new InputStreamReader(responseStream, encoding)); String tempLine = rd.readLine(); StringBuffer tempStr = new StringBuffer(); String crlf = System.getProperty("line.separator"); while (tempLine != null) { tempStr.append(tempLine); tempStr.append(crlf); tempLine = rd.readLine(); } responseContent = tempStr.toString(); } else responseContent = request.getResponseBodyAsString(); Header locationHeader = request.getResponseHeader("location"); // 返回代码为302,301时,表示页面己经重定向,则重新请求location的url,这在 // 一些登录授权取cookie时很重要 if (locationHeader != null) { String redirectUrl = locationHeader.getValue(); this.doRequest(redirectUrl, null, null, null); } } catch (HttpException e) { throw new Exception(e.getMessage()); } catch (IOException e) { throw new Exception(e.getMessage()); } finally { if (rd != null) try { rd.close(); } catch (IOException e) { throw new Exception(e.getMessage()); } if (responseStream != null) try { responseStream.close(); } catch (IOException e) { throw new Exception(e.getMessage()); } } return responseContent; } /** * 特殊请求数据,这样的请求往往会出现redirect本身而出现递归死循环重定向 所以单独写成一个请求方法 * 比如现在请求的url为:http://localhost:8080/demo/index.jsp 返回代码为302 * 头部信息中location值为:http://localhost:8083/demo/index.jsp * 这时httpclient认为进入递归死循环重定向,抛出CircularRedirectException异常 * * @param url * @return * @throws CustomException */ public String doSpecialRequest(String url, int count, String encoding) throws Exception { String str = null; InputStream responseStream = null; BufferedReader rd = null; GetMethod getRequest = new GetMethod(url); // 关闭httpclient自动重定向动能 getRequest.setFollowRedirects(false); try { this.client.executeMethod(getRequest); Header header = getRequest.getResponseHeader("location"); if (header != null) { // 请求重定向后的URL,count同时加1 this.doSpecialRequest(header.getValue(), count + 1, encoding); } // 这里用count作为标志位,当count为0时才返回请求的URL文本, // 这样就可以忽略所有的递归重定向时返回文本流操作,提高性能 if (count == 0) { getRequest = new GetMethod(url); getRequest.setFollowRedirects(false); this.client.executeMethod(getRequest); responseStream = getRequest.getResponseBodyAsStream(); rd = new BufferedReader(new InputStreamReader(responseStream, encoding)); String tempLine = rd.readLine(); StringBuffer tempStr = new StringBuffer(); String crlf = System.getProperty("line.separator"); while (tempLine != null) { tempStr.append(tempLine); tempStr.append(crlf); tempLine = rd.readLine(); } str = tempStr.toString(); } } catch (HttpException e) { throw new Exception(e.getMessage()); } catch (IOException e) { throw new Exception(e.getMessage()); } finally { getRequest.releaseConnection(); if (rd != null) try { rd.close(); } catch (IOException e) { throw new Exception(e.getMessage()); } if (responseStream != null) try { responseStream.close(); } catch (IOException e) { throw new Exception(e.getMessage()); } } return str; } public static void main(String[] args) throws Exception { HttpRequestProxy hrp = new HttpRequestProxy(); Map date = new HashMap(); date.put("jyidApplet", "1"); date.put("codeNumApplet", "1"); date.put("jymxIdApplet", "447"); date.put("patientIdApplet", "1118"); String str = hrp.doRequest("http://127.0.0.1:8080/lis/mz/addTM",date, null, null); System.out.println(str); } } ```

Java中httpclient分页抓取图片急求代码

这是网址:http://i.wap.58.com/wapimg/?page=1&infoid=25150533913132&cate=zufang&citylistname=bj

httpclient访问Nginx集群404错误

在使用httpClient范文Nginx做的集群时,出现404错误。 在浏览器中访问正常。 发现原因是不知道哪块配置的不正确导致url套了两层二级目录。 nginx集群配置如下 upstream weibo { ip_hash; server 10.30.30.152:8080 weight=2 fail_timeout=5; server 10.30.30.155:8080 weight=2 fail_timeout=5; server 10.30.30.155:8081 weight=2 fail_timeout=5; server 10.30.30.156:8080 weight=2 fail_timeout=5; server 10.30.30.156:8081 weight=2 fail_timeout=5; } location /weibo { proxy_connect_timeout 30; proxy_send_timeout 30; proxy_read_timeout 30; proxy_pass http://weibo; proxy_set_header X-Real-IP $remote_addr; } HttpClient访问的部分代码如下: String result = httpclient.postForm( "http://lswx.lnd.com.cn/weibo/ws/rest/", new PostParameter[] { new PostParameter("eap_username", "admin"), new PostParameter("eap_password", 1), new PostParameter("boId", "weibomanagedc_memberFunctionBO_bo"), new PostParameter("methodName", "getMemberScoreInfo"), new PostParameter("returnType", "String"), new PostParameter("parameters", "[{String:{userid:\"781607\",currentPage:1}}]")}); System.out.println(result); 正常的url应该是http://lswx.lnd.com.cn/weibo/ws/rest/ 可是在返回的404信息中url变成了 <h1>HTTP Status 404 - /weibo/weibo/ws/rest/;jsessionid=EA56FE93960229138ECC634E697123C6</h1> 有两个weibo 有没有大侠遇到过类似问题,指点一二 万谢,在线等

使用HttpClient验证用户名和密码

<div class="post-text" itemprop="text"> <p>I am trying to send a POST request to a php file which then sends back a json message for username and password authentication. with my code I get an error ArrayIndexOutOfBoundsException: length=0; index=0 on this line:</p> <pre><code>HttpGet get=new HttpGet(strings[0]); </code></pre> <p>In my code, when the login button is clicked, it calls an asyncTask class which then runs the application. it crashes before I can even test the code but I am not sure why. I am new to HttpClient so please be gentle. This is my snippet of code in the asynctask class</p> <pre><code>public class DownloadFilesTask extends AsyncTask&lt;Void, Void, Void&gt; { private String name, pwd; private LoginActivity loginActivity; boolean bloggedIn; public DownloadFilesTask(LoginActivity loginActivity,String name, String pwd){ this.loginActivity=loginActivity; this.name=name; this.pwd=pwd; } @Override protected Void doInBackground(Void... voids) { HttpClient httpClient=new DefaultHttpClient(); HttpGet get=new HttpGet(); try { URI website=new URI("login.php"); get.setURI(website); } catch (URISyntaxException e) { e.printStackTrace(); } HttpPost httpPost=new HttpPost("login.php"); List&lt;NameValuePair&gt; nameValuePairs=new ArrayList&lt;NameValuePair&gt;(2); String result=null; nameValuePairs.add(new BasicNameValuePair("name", name)); nameValuePairs.add(new BasicNameValuePair("password", pwd)); try { httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } HttpResponse response = null; //error try { response = httpClient.execute(httpPost); } catch (IOException e) { e.printStackTrace(); } HttpEntity entity=response.getEntity(); InputStream instream= null; try { instream = entity.getContent(); } catch (IOException e) { e.printStackTrace(); } result=convertStreamToString(instream); try { instream.close(); } catch (IOException e) { e.printStackTrace(); } if (Utility.isNotNull(name) &amp;&amp; Utility.isNotNull(pwd)) { RequestParams params = new RequestParams(); if (Utility.validate(name, pwd)) { params.put("username", name); params.put("password", pwd); bloggedIn=true; onPostExecute(); } else { loginActivity.InvalidToast(); } } else { loginActivity.EmptyToast(); } return null; } private String convertStreamToString(InputStream instream) { BufferedReader reader=new BufferedReader(new InputStreamReader(instream)); StringBuilder sb=new StringBuilder(); String line=null; try { while ((line=reader.readLine())!=null){ sb.append(line + " "); } } catch (IOException e) { e.printStackTrace(); }finally{ try { instream.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } protected void onPostExecute(){ if (bloggedIn=true) { loginActivity.navigatetoMainActivity(); }else{ loginActivity.InvalidToast(); } } private static class Utility { static Pattern pattern; static Matcher matcher; static Pattern pattern1; static Matcher matcher1; static String NAME_PATTERN="ABCDEF"; static String PWD_PATTERN="ghijkl"; public static boolean validate(String name,String pwd){ pattern=Pattern.compile(NAME_PATTERN); pattern1=Pattern.compile(PWD_PATTERN); matcher=pattern.matcher(name); matcher1=pattern1.matcher(pwd); return matcher.matches()&amp;&amp; matcher1.matches(); } public static boolean isNotNull(String name) { return name!=null &amp;&amp; name.trim().length()&gt;0 ? true: false; } } </code></pre> <p>}</p> </div>

HTTPClient提交失败,fiddler提交成功是什么原因?

模拟提交数据到其他公司api接口,代码如下,提交到后台后返回:{"error":"Cannot read property 'enable' of null"},服务器500错误 ;通过fiddler抓取提交的数据,在fiddler重新提交又是正常的,求助高手啊。 HTTP/1.1 500 Internal Server Error Content-Type: application/json; charset=utf-8 Content-Length: 49 Date: Sun, 03 May 2020 01:29:59 GMT X-XSS-Protection: 1;mode=block Strict-Transport-Security: max-age=31536000 {"error":"Cannot read property 'enable' of null"} fiddler不做任何修改重新提交: HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 Content-Length: 63 Date: Sun, 03 May 2020 01:31:47 GMT X-XSS-Protection: 1;mode=block Strict-Transport-Security: max-age=31536000 {"result":"5eae1f037eab9e653ce863b8","errcode":0,"errmsg":"OK"} 代码如下: public static HttpResponse sendAddOrderJsonPost(String url, String json, UserAuth userAuth) { HttpResponse response = null; HttpPost post = new HttpPost(url); post.setConfig(HttpsGlobal.config); post.setHeader("Host", userAuth.getHost()); post.setHeader("Connection", "keep-alive"); post.setHeader("Accept", "application/json, text/plain, */*"); post.setHeader("Origin", userAuth.getOrigin); post.setHeader("User-Agent", userAuth.getUser_agent()); post.setHeader("Content-Type", "application/json; charset=UTF-8"); post.setHeader("Referer", url); post.setHeader("Accept-Encoding", "gzip, deflate"); post.setHeader("Accept-Language", "zh-cn-#hans"); post.setHeader("Cookie", userAuth.getCookies()); try { StringEntity requestEntity = new StringEntity(json, "UTF-8"); post.setEntity(requestEntity); response = HttpsGlobal.client.execute(post); } catch (SocketTimeoutException e1) { HttpsGlobal.logger.error("SocketTimeoutException!"); } catch (ConnectTimeoutException e2) { HttpsGlobal.logger.error("ConnectTimeoutException"); } catch (ConnectException e3) { HttpsGlobal.logger.error("ConnectException"); } catch (IOException e4) { HttpsGlobal.logger.error("IOException"); } catch (Exception e5) { HttpsGlobal.logger.error("Exception"); } return response; } ``` ```

Python可以这样学(第一季:Python内功修炼)

董付国系列教材《Python程序设计基础》、《Python程序设计(第2版)》、《Python可以这样学》配套视频,讲解Python 3.5.x和3.6.x语法、内置对象用法、选择与循环以及函数设计与使用、lambda表达式用法、字符串与正则表达式应用、面向对象编程、文本文件与二进制文件操作、目录操作与系统运维、异常处理结构。

获取Linux下Ftp目录树并逐步绑定到treeview

在linux下抓取目录树,双击后获取该节点子节点(逐步生成)。另外有两个类,一个是windows下的(一次性获取目录树),一个是linux下的(足部获取目录树)

NS网络模拟和协议仿真源代码

NS网络模拟和协议仿真源代码,包含代码说明及协议分析

简单的NS3网络模拟仿真(计算机网络作业)

简单的NS3网络模拟仿真,内附有PPT演示。论文评述。以及简单的安装教程。

手把手实现Java图书管理系统(附源码)

【超实用课程内容】 本课程演示的是一套基于Java的SSM框架实现的图书管理系统,主要针对计算机相关专业的正在做毕设的学生与需要项目实战练习的java人群。详细介绍了图书管理系统的实现,包括:环境搭建、系统业务、技术实现、项目运行、功能演示、系统扩展等,以通俗易懂的方式,手把手的带你从零开始运行本套图书管理系统,该项目附带全部源码可作为毕设使用。 【课程如何观看?】 PC端:https://edu.csdn.net/course/detail/27513 移动端:CSDN 学院APP(注意不是CSDN APP哦) 本课程为录播课,课程2年有效观看时长,大家可以抓紧时间学习后一起讨论哦~ 【学员专享增值服务】 源码开放 课件、课程案例代码完全开放给你,你可以根据所学知识,自行修改、优化

三个项目玩转深度学习(附1G源码)

从事大数据与人工智能开发与实践约十年,钱老师亲自见证了大数据行业的发展与人工智能的从冷到热。事实证明,计算机技术的发展,算力突破,海量数据,机器人技术等,开启了第四次工业革命的序章。深度学习图像分类一直是人工智能的经典任务,是智慧零售、安防、无人驾驶等机器视觉应用领域的核心技术之一,掌握图像分类技术是机器视觉学习的重中之重。针对现有线上学习的特点与实际需求,我们开发了人工智能案例实战系列课程。打造:以项目案例实践为驱动的课程学习方式,覆盖了智能零售,智慧交通等常见领域,通过基础学习、项目案例实践、社群答疑,三维立体的方式,打造最好的学习效果。

150讲轻松搞定Python网络爬虫

【为什么学爬虫?】 &nbsp; &nbsp; &nbsp; &nbsp;1、爬虫入手容易,但是深入较难,如何写出高效率的爬虫,如何写出灵活性高可扩展的爬虫都是一项技术活。另外在爬虫过程中,经常容易遇到被反爬虫,比如字体反爬、IP识别、验证码等,如何层层攻克难点拿到想要的数据,这门课程,你都能学到! &nbsp; &nbsp; &nbsp; &nbsp;2、如果是作为一个其他行业的开发者,比如app开发,web开发,学习爬虫能让你加强对技术的认知,能够开发出更加安全的软件和网站 【课程设计】 一个完整的爬虫程序,无论大小,总体来说可以分成三个步骤,分别是: 网络请求:模拟浏览器的行为从网上抓取数据。 数据解析:将请求下来的数据进行过滤,提取我们想要的数据。 数据存储:将提取到的数据存储到硬盘或者内存中。比如用mysql数据库或者redis等。 那么本课程也是按照这几个步骤循序渐进的进行讲解,带领学生完整的掌握每个步骤的技术。另外,因为爬虫的多样性,在爬取的过程中可能会发生被反爬、效率低下等。因此我们又增加了两个章节用来提高爬虫程序的灵活性,分别是: 爬虫进阶:包括IP代理,多线程爬虫,图形验证码识别、JS加密解密、动态网页爬虫、字体反爬识别等。 Scrapy和分布式爬虫:Scrapy框架、Scrapy-redis组件、分布式爬虫等。 通过爬虫进阶的知识点我们能应付大量的反爬网站,而Scrapy框架作为一个专业的爬虫框架,使用他可以快速提高我们编写爬虫程序的效率和速度。另外如果一台机器不能满足你的需求,我们可以用分布式爬虫让多台机器帮助你快速爬取数据。 &nbsp; 从基础爬虫到商业化应用爬虫,本套课程满足您的所有需求! 【课程服务】 专属付费社群+每周三讨论会+1v1答疑

cuda开发cutilDLL

包括cutil32.dll、cutil32D.dll、cutil32.lib、cutil32D.lib,以及附带的glew32.lib/freeglut.lib

深度学习原理+项目实战+算法详解+主流框架(套餐)

深度学习系列课程从深度学习基础知识点开始讲解一步步进入神经网络的世界再到卷积和递归神经网络,详解各大经典网络架构。实战部分选择当下最火爆深度学习框架PyTorch与Tensorflow/Keras,全程实战演示框架核心使用与建模方法。项目实战部分选择计算机视觉与自然语言处理领域经典项目,从零开始详解算法原理,debug模式逐行代码解读。适合准备就业和转行的同学们加入学习! 建议按照下列课程顺序来进行学习 (1)掌握深度学习必备经典网络架构 (2)深度框架实战方法 (3)计算机视觉与自然语言处理项目实战。(按照课程排列顺序即可)

Tensorflow与python3.7适配版本

tensorflow与python3.7匹配的最新库,更新了python3.7以后可以自行下载,或者去国外python的扩展包下载界面自行下载。

4小时玩转微信小程序——基础入门与微信支付实战

这是一个门针对零基础学员学习微信小程序开发的视频教学课程。课程采用腾讯官方文档作为教程的唯一技术资料来源。杜绝网络上质量良莠不齐的资料给学员学习带来的障碍。 视频课程按照开发工具的下载、安装、使用、程序结构、视图层、逻辑层、微信小程序等几个部分组织课程,详细讲解整个小程序的开发过程

专为程序员设计的数学课

<p> 限时福利限时福利,<span>15000+程序员的选择!</span> </p> <p> 购课后添加学习助手(微信号:csdn590),按提示消息领取编程大礼包!并获取讲师答疑服务! </p> <p> <br> </p> <p> 套餐中一共包含5门程序员必学的数学课程(共47讲) </p> <p> 课程1:《零基础入门微积分》 </p> <p> 课程2:《数理统计与概率论》 </p> <p> 课程3:《代码学习线性代数》 </p> <p> 课程4:《数据处理的最优化》 </p> <p> 课程5:《马尔可夫随机过程》 </p> <p> <br> </p> <p> 哪些人适合学习这门课程? </p> <p> 1)大学生,平时只学习了数学理论,并未接触如何应用数学解决编程问题; </p> <p> 2)对算法、数据结构掌握程度薄弱的人,数学可以让你更好的理解算法、数据结构原理及应用; </p> <p> 3)看不懂大牛代码设计思想的人,因为所有的程序设计底层逻辑都是数学; </p> <p> 4)想学习新技术,如:人工智能、机器学习、深度学习等,这门课程是你的必修课程; </p> <p> 5)想修炼更好的编程内功,在遇到问题时可以灵活的应用数学思维解决问题。 </p> <p> <br> </p> <p> 在这门「专为程序员设计的数学课」系列课中,我们保证你能收获到这些:<br> <br> <span> </span> </p> <p class="ql-long-24357476"> <span class="ql-author-24357476">①价值300元编程课程大礼包</span> </p> <p class="ql-long-24357476"> <span class="ql-author-24357476">②应用数学优化代码的实操方法</span> </p> <p class="ql-long-24357476"> <span class="ql-author-24357476">③数学理论在编程实战中的应用</span> </p> <p class="ql-long-24357476"> <span class="ql-author-24357476">④程序员必学的5大数学知识</span> </p> <p class="ql-long-24357476"> <span class="ql-author-24357476">⑤人工智能领域必修数学课</span> </p> <p> <br> 备注:此课程只讲程序员所需要的数学,即使你数学基础薄弱,也能听懂,只需要初中的数学知识就足矣。<br> <br> 如何听课? </p> <p> 1、登录CSDN学院 APP 在我的课程中进行学习; </p> <p> 2、登录CSDN学院官网。 </p> <p> <br> </p> <p> 购课后如何领取免费赠送的编程大礼包和加入答疑群? </p> <p> 购课后,添加助教微信:<span> csdn590</span>,按提示领取编程大礼包,或观看付费视频的第一节内容扫码进群答疑交流! </p> <p> <img src="https://img-bss.csdn.net/201912251155398753.jpg" alt=""> </p>

实现简单的文件系统

实验内容: 通过对具体的文件存储空间的管理、文件的物理结构、目录结构和文件操作的实现,加深对文件系统内部功能和实现过程的理解。 要求: 1.在内存中开辟一个虚拟磁盘空间作为文件存储器,在其上实现一个简

机器学习初学者必会的案例精讲

通过六个实际的编码项目,带领同学入门人工智能。这些项目涉及机器学习(回归,分类,聚类),深度学习(神经网络),底层数学算法,Weka数据挖掘,利用Git开源项目实战等。

四分之一悬架模型simulink.7z

首先建立了四分之一车辆悬架系统的数学模型,应用MATLAB/Simulink软件建立该系统的仿真模型,并输入路面激励为随机激励,控制不同的悬架刚度和阻尼,选用最优的参数得到车辆悬架的振动加速度变化曲线

MFC一站式终极全套课程包

该套餐共包含从C小白到C++到MFC的全部课程,整套学下来绝对成为一名C++大牛!!!

C++语言基础视频教程

C++语言基础视频培训课程:本课与主讲者在大学开出的程序设计课程直接对接,准确把握知识点,注重教学视频与实践体系的结合,帮助初学者有效学习。本教程详细介绍C++语言中的封装、数据隐藏、继承、多态的实现等入门知识;主要包括类的声明、对象定义、构造函数和析构函数、运算符重载、继承和派生、多态性实现等。 课程需要有C语言程序设计的基础(可以利用本人开出的《C语言与程序设计》系列课学习)。学习者能够通过实践的方式,学会利用C++语言解决问题,具备进一步学习利用C++开发应用程序的基础。

Java8零基础入门视频教程

这门课程基于主流的java8平台,由浅入深的详细讲解了java SE的开发技术,可以使java方向的入门学员,快速扎实的掌握java开发技术!

HoloLens2开发入门教程

本课程为HoloLens2开发入门教程,讲解部署开发环境,安装VS2019,Unity版本,Windows SDK,创建Unity项目,讲解如何使用MRTK,编辑器模拟手势交互,打包VS工程并编译部署应用到HoloLens上等。

C/C++学习指南全套教程

C/C++学习的全套教程,从基本语法,基本原理,到界面开发、网络开发、Linux开发、安全算法,应用尽用。由毕业于清华大学的业内人士执课,为C/C++编程爱好者的教程。

pokemmo的资源

pokemmo必须的4个rom 分别为绿宝石 火红 心金 黑白 还有汉化补丁 资源不错哦 记得下载

test_head.py

本文件主要是针对使用dlib的imglab标注工具标记的目标检测框和关键点检测而生成的xml文件, 转换为coco数据集格式.

Java面试史上最全的JAVA专业术语面试100问 (前1-50)

前言: 说在前面, 面试题是根据一些朋友去面试提供的,再就是从网上整理了一些。 先更新50道,下一波吧后面的也更出来。 求赞求关注!! 废话也不多说,现在就来看看有哪些面试题 1、面向对象的特点有哪些? 抽象、继承、封装、多态。 2、接口和抽象类有什么联系和区别? 3、重载和重写有什么区别? 4、java有哪些基本数据类型? 5、数组有没有length()方法?String有没有length()方法? 数组没有length()方法,它有length属性。 String有length()方法。 集合求长度用

2019 AI开发者大会

2019 AI开发者大会(AI ProCon 2019)是由中国IT社区CSDN主办的AI技术与产业年度盛会。多年经验淬炼,如今蓄势待发:2019年9月6-7日,大会将有近百位中美顶尖AI专家、知名企业代表以及千余名AI开发者齐聚北京,进行技术解读和产业论证。我们不空谈口号,只谈技术,诚挚邀请AI业内人士一起共铸人工智能新篇章!

linux“开发工具三剑客”速成攻略

工欲善其事,必先利其器。Vim+Git+Makefile是Linux环境下嵌入式开发常用的工具。本专题主要面向初次接触Linux的新手,熟练掌握工作中常用的工具,在以后的学习和工作中提高效率。

DirectX修复工具V4.0增强版

DirectX修复工具(DirectX Repair)是一款系统级工具软件,简便易用。本程序为绿色版,无需安装,可直接运行。 本程序的主要功能是检测当前系统的DirectX状态,如果发现异常则进行修复

20行代码教你用python给证件照换底色

20行代码教你用python给证件照换底色

2019 Python开发者日-培训

本次活动将秉承“只讲技术,拒绝空谈”的理念,邀请十余位身处一线的Python技术专家,重点围绕Web开发、自动化运维、数据分析、人工智能等技术模块,分享真实生产环境中使用Python应对IT挑战的真知灼见。此外,针对不同层次的开发者,大会还安排了深度培训实操环节,为开发者们带来更多深度实战的机会。

我以为我对Mysql事务很熟,直到我遇到了阿里面试官

太惨了,面试又被吊打

相关热词 c#中如何设置提交按钮 c#帮助怎么用 c# 读取合并单元格的值 c#带阻程序 c# 替换span内容 c# rpc c#控制台点阵字输出 c#do while循环 c#调用dll多线程 c#找出两个集合不同的
立即提问