wifi发动图片失败,4G就可以
使用android 发动图文到后台nginx,刚开始wifi还可以发到服务器,过一段时间,就不可以了,出现nginx log 400错误,有的时候还出现499,查了一下有的是说客户端提前关闭导致的,有的说请求 head 过大,我也体哦正了client_header_buffer_size 256k;
large_client_header_buffers 4 512k;还是出现400错误。无意间偶然使用4G 忽然就可以了,后来试了下,4G 就可以,wifi就时常不行,不知到怎么回事,有了解的情况的吗?我都搞了一段时间了。
android 上传head部分
HttpURLConnection conn = null;
try {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO) {
System.setProperty("http.keepAlive", "false");
}
URL url = new URL(this.url);
conn = (HttpURLConnection) url.openConnection();
conn.setChunkedStreamingMode(0);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Charsert", "UTF-8");
if (Build.VERSION.SDK != null && Build.VERSION.SDK_INT > 13) {
conn.setRequestProperty("Connection", "close");
}
conn.setRequestProperty("Content-Type", CONTENT_TYPE + ";boundary="
+ BOUNDARY);
if (CurrentUser.isAuthenticated()) {
CurrentUserInfo currentUser = CurrentUser.getCurrentUser();
conn.setRequestProperty("Cookie",
"sessionid=" + currentUser.getSessionid()
+ ";csrftoken=" + currentUser.getCsrftoken());
conn.setRequestProperty("X-CSRFToken",
currentUser.getCsrftoken());
conn.setRequestProperty("CSRFTOKEN", currentUser.getCsrftoken());
conn.setRequestProperty("HTTP_COOKIE", "sessionid="
+ currentUser.getSessionid() + ";csrftoken="
+ currentUser.getCsrftoken());
}
conn.setConnectTimeout(connectTimeout);
conn.setReadTimeout(readTimeout);
conn.connect();
new Thread(new InterruptThread(Thread.currentThread(), conn,HttpUpload.TIMER_TIMEOUT_WRITE_ARCHIVE)).start();
DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
uploadParams(dos);//上传图文函数
后台nginx 配置
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 256;
client_header_buffer_size 256k;
large_client_header_buffers 4 512k;
client_max_body_size 100M;
client_body_buffer_size 256k;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;
tcp_nopush on;
proxy_ignore_client_abort on;
keepalive_timeout 0;
tcp_nodelay on;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";