Open happylwg opened 7 years ago
我多线程爬虫的时候也遇到了同样的问题,请问楼主是怎么解决的
这是我的解决办法:
import jodd.http.HttpRequest; import jodd.http.HttpResponse; import lombok.Data;
/**
Created by watermelon on 2019/04/09 */ public class ZimgUtils {
public static String upload(String url, String zimgUrl) { return upload(zimgUrl, download(url)); }
private static byte[] download(String url) { HttpRequest httpRequest=HttpRequest.get(url); HttpResponse httpResponse=httpRequest.send(); return httpResponse.bodyBytes(); }
private static String upload(String zimgUrl, byte[] bytes) { HttpRequest httpRequest=HttpRequest.post(zimgUrl) .body(bytes,"jpeg"); HttpResponse httpResponse=httpRequest.send(); return httpResponse.bodyText(); }
@Data public class Response{ private Boolean ret; private Error error; private Info info;
@Data
public class Info{
private String md5;
private Long size;
}
@Data
public class Error{
private Integer code;
private String message;
}
} }
com.mashape.unirest.http.exceptions.UnirestException: org.apache.http.NoHttpResponseException: imagestest.****.com:4869 failed to respond at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:143) at com.mashape.unirest.request.BaseRequest.asString(BaseRequest.java:56) at com.fcar.base.zimg.ZIMGClient.upload(ZIMGClient.java:114) at com.fcar.base.zimg.ZIMGController.upload(ZIMGController.java:34) at sun.reflect.GeneratedMethodAccessor615.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606)