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(带特殊字符),返回结果正确。

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() ``` 有同学遇到过吗?

使用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 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(); }

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 模拟登陆网站时,网站重定向,我该怎么进入后继的网页啊!

我用的是httpclient4.3.6 。我模拟登陆我们学校的网站,获取了cookies,但是我用httpwatch看 有重定向的问题,我不知道怎么进入后面的网页!求解!我贴上代码,求代码详解,谢谢!!!小弟初学java 现需要做这个操作,很是艰难呀!感激不尽!

有人能简单的给说下 socket httpclient 及java.net.url的区别 联系 应用方式吗

rt有人能简单的给说下 socket httpclient 及java.net.url的区别 联系 应用方式吗

有关java使用httpclient模拟httppost请求的问题!求大神帮忙!

我现在在写一个eclipse的插件,主要是通过java向服务器发出httppost的请求,调用一些比如登陆啊等等的服务器端api。就是模拟浏览器操作 但是现在遇到了一个问题,服务器端的程序要检查浏览器是不是支持javascript的(因为好像服务器的那边根本没有做静态页面,所有的html都是javascript动态加载出来的),所以我现在调不到那边的api了,发送任何请求收到的response都是一样的,都是一个提示您浏览器不支持javascript的错误页面 求问怎么才能越过这一关啊,我用的是apache的httpclient,有没有什么方法能让java模拟发出的post请求也能”支持“javascript啊,谢谢各位了!!感激不尽!

使用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 连接一个需要Signature验证的API

使用httpClent 4.x 连接一个需要Signature验证的API 一直返回401 ``` HTTP/1.1 401 Unauthorized Server: Apache-Coyote/1.1 X-Application-Context: bootstrap Authorization: WWW-Authenticate: Signature realm="World-Check One API",algorithm="hmac-sha256",headers="(request-target) host date content-type content-length Transfer-Encoding: chunked Date: Fri, 21 Oct 2016 12:36:54 GMT ``` 我确认我的加密方法已经正确,我只是把Signature Authenticate 加到Header,这样是否正确? ``` // httpClient 连接到url final HttpGet request = new HttpGet(httpUrl); request.setHeader("Date", gmtDate); request.setHeader("Authorization", auth); final HttpClient client = HttpClientBuilder.create().build(); final HttpResponse response = client.execute(request); final int statusCode = response.getStatusLine().getStatusCode(); ``` ``` // 加密 private String getSignature(final String dataToSign) { logger.info("***** dataToSign : " + dataToSign +" *****"); final String signature = Hmac.encodeHmacSHA256(dataToSign.getBytes(), apiSecret.getBytes()); logger.info("***** signature : " + signature +" *****"); return signature; } // 拼装成Authorisation private String getAuthorisation(final String signature) { final StringBuffer sb = new StringBuffer(""); sb.append("Signature keyId=\"").append(apiKey); sb.append("\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date\",signature=\""); sb.append(signature).append("\""); logger.info("***** dataToSign : " + sb.toString() +" *****"); return sb.toString(); } ```

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

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

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

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

为什么使用HttpClient发送json总是返回400?

android手机端需要发送一个json格式的数据,返回的也是json数据。 现在问题出现在,我无论怎么写都返回400,Bad Request。 问题出在哪儿呢?且看代码,感觉该设置的都设置了。 [code="java"] /** * POST获取服务端数据,发送的是json格式的数据 * @param urlString * @param json 需要发送的json数据 * @return * @throws ClientProtocolException * @throws IOException */ public String getDataFromServerByPostForJson(String urlString,JSONObject json) throws ClientProtocolException, IOException{ String strResult = null; HttpClient client = new DefaultHttpClient(); StringEntity entity = new StringEntity(json.toString()); entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/x-www-form-urlencoded"));//"application/octet-stream" entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_ENCODING,HTTP.UTF_8)); HttpPost post = new HttpPost(urlString); post.setHeader("Accept", "application/json"); post.setHeader("Content-Type", "application/json"); post.setEntity(entity); HttpResponse response = client.execute(post); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { strResult = EntityUtils.toString(response.getEntity(), HTTP.UTF_8); }else{ post.abort(); strResult = "Error Response code " + response.getStatusLine().getStatusCode() + " :" + response.getStatusLine().toString(); Log.i("tag", strResult); return null; } return strResult; } [/code] 有碰到类似的朋友吗?

使用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请求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使用post请求抓取数据出现异常alert: internal_error

使用HttpClient去抓取网站数据包,出现了javax.net.ssl.SSLException: Received fatal alert: internal_error,异常只打印了这句话,在抓取其他网站的数据使用没问题,可以抓这个网站post请求就出现了这个问题,在执行HttpResponse httpResponse = httpClient.execute(httpRequest); 出现这个问题,大部分post都是没问题的![图片说明] (https://img-ask.csdn.net/upload/201908/18/1566141194_855160.png),报错信息就这么多,后面的就是业务代码了,抓取其他网站是post,get都是没问题,这个网站一post就是出问题了,一直报这个错误,卡在这里很久了,使用原生的post又没有问题,可是这个封装的post也是原生的基础上封装的,大部分都是没问题,请求这个网站就是有问题,求大佬解惑。

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

C++(数据结构与算法)78:---分而治之

一、分而治之的思想 分而治之方法与软件设计的模块化方法非常相似 分而治之通常不用于解决问题的小实例,而要解决一个问题的大实例。一般步骤为: ①把一个大实例分为两个或多个更小的实例 ②分别解决每个小实例 ③把这些小实例的解组合成原始大实例的解 二、实际应用之找出假币 问题描述 一个袋子有16个硬币,其中只有一个是假币,这个假币比其他的真币重量轻(其他所有真币的重量都是相同的)...

springboot+jwt实现token登陆权限认证

一 前言 此篇文章的内容也是学习不久,终于到周末有时间码一篇文章分享知识追寻者的粉丝们,学完本篇文章,读者将对token类的登陆认证流程有个全面的了解,可以动态搭建自己的登陆认证过程;对小项目而已是个轻量级的认证机制,符合开发需求;更多精彩原创内容关注公主号知识追寻者,读者的肯定,就是对作者的创作的最大支持; 二 jwt实现登陆认证流程 用户使用账号和面发出post请求 服务器接受到请求后使用私...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

win10暴力查看wifi密码

刚才邻居打了个电话说:喂小灰,你家wifi的密码是多少,我怎么连不上了。 我。。。 我也忘了哎,就找到了一个好办法,分享给大家: 第一种情况:已经连接上的wifi,怎么知道密码? 打开:控制面板\网络和 Internet\网络连接 然后右击wifi连接的无线网卡,选择状态 然后像下图一样: 第二种情况:前提是我不知道啊,但是我以前知道密码。 此时可以利用dos命令了 1、利用netsh wlan...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

程序员写出这样的代码,能不挨骂吗?

当你换槽填坑时,面对一个新的环境。能够快速熟练,上手实现业务需求是关键。但是,哪些因素会影响你快速上手呢?是原有代码写的不够好?还是注释写的不够好?昨夜...

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

!大部分程序员只会写3年代码

如果世界上都是这种不思进取的软件公司,那别说大部分程序员只会写 3 年代码,恐怕就没有程序员这种职业。

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

早上躺尸,晚上干活:硅谷科技公司这么流行迟到?

硅谷科技公司上班时间OPEN早已不是什么新鲜事,早九晚五是常态,但有很多企业由于不打卡,员工们10点、11点才“姗姗来迟”的情况也屡见不鲜。 这种灵活的考勤制度为人羡慕,甚至近年来,国内某些互联网企业也纷纷效仿。不过,硅谷普遍弹性的上班制度是怎么由来的呢?这种“流行性迟到”真的有那么轻松、悠哉吗? 《动态规划专题班》 课程试听内容: 动态规划的解题要领 动态规划三大类 求最值/计数/可行性 常...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

Python爬虫,高清美图我全都要(彼岸桌面壁纸)

爬取彼岸桌面网站较为简单,用到了requests、lxml、Beautiful Soup4

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

Java岗开发3年,公司临时抽查算法,离职后这几题我记一辈子

前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...

立即提问
相关内容推荐