android - crlf 预计在块 httpclient 的末尾
问题描述
我正在尝试从我的服务器中保存数据。我正在使用 HttpClient 来获取我的数据。但有时未获取数据,并且在块的末尾显示了名为 crlf 的错误。我尝试在此链接之后更改 jmeter 属性中的缓冲区大小,但问题未解决。我在下面给出我的代码。找不到解决方案。需要帮忙。
FavouriteCategoriesJsonParser.java
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import org.apache.http.util.EntityUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
public class FavouriteCategoriesJsonParser {
public static ArrayList<String> selectedCategories = new ArrayList<>();
public ArrayList<Category> getParsedCategories() {
String JsonFavouriteCategories = "";
ArrayList<Category> MyArraylist = new ArrayList<>();
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://xxxxx.com.yy/test_file/get_value.php");
try {
// ServiceHandler jsonParser = new ServiceHandler();
// String json = jsonParser.makeServiceCall(campaign_credit,ServiceHandler.GET,params);
HttpResponse httpResponse = httpClient.execute(httpGet);
JsonFavouriteCategories = EntityUtils.toString(httpResponse.getEntity());
JSONArray jsonArray = new JSONArray(JsonFavouriteCategories);
for (int i = 0; i < jsonArray.length(); i++) {
Category genres = new Category();
JSONObject MyJsonObject = jsonArray.getJSONObject(i);
genres.setCateogry_id(MyJsonObject.getString("DOC_CODE"));
genres.setCategory_Name(MyJsonObject.getString("DOC_CODE"));
genres.setCategory_Name2(MyJsonObject.getString("DOC_NAME"));
genres.setSelected(Boolean.parseBoolean(MyJsonObject.getString("SELECTED")));
MyArraylist.add(genres);
if (MyJsonObject.getString("SELECTED").equals("true")) {
selectedCategories.add(MyJsonObject.getString("DOC_CODE"));
}
}
} catch (Exception e) {
e.printStackTrace();
}
return MyArraylist;
}
}
FatchData.java
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import androidx.appcompat.app.AppCompatActivity;
import com.myproject.demo.adapter.CategoryAdapter;
import com.myproject.demo.model.Category;
import com.myproject.demo.FavouriteCategoriesJsonParser;
//PcProposalDoc
public class PcProposalDoc extends AppCompatActivity {
Context context;
ArrayList<Category> array_list;
FavouriteCategoriesJsonParser categoryJsonParser;
String categoriesCsv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.proposal_activity_main);
Typeface fontFamily = Typeface.createFromAsset(getAssets(), "fonts/fontawesome.ttf");
Button button = (Button) findViewById(R.id.selectCategoryButton);
context = this;
new asyncTask_getCategories().execute();
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
categoriesCsv = FavouriteCategoriesJsonParser.selectedCategories.toString();
categoriesCsv = categoriesCsv.substring(1, categoriesCsv.length() - 1);
if (categoriesCsv.length() > 0) {
new asyncTask_insertUpdatefavouriteCategories().execute();
} else {
Toast.makeText(context, "Please Select Doctor", Toast.LENGTH_SHORT).show();
}
}
});
}
public class asyncTask_getCategories extends AsyncTask<Void, Void, Void> {
ProgressDialog dialog = new ProgressDialog(context);
@Override
protected void onPreExecute() {
dialog.setTitle("Please wait...");
dialog.setMessage("Loading Doctors!");
dialog.show();
array_list = new ArrayList<>();
categoryJsonParser = new FavouriteCategoriesJsonParser();
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
array_list = categoryJsonParser.getParsedCategories();
return null;
}
@Override
protected void onPostExecute(Void s) {
ListView mListViewBooks = (ListView) findViewById(R.id.category_listView);
final CategoryAdapter categoryAdapter = new CategoryAdapter(context, R.layout.row_category, array_list);
mListViewBooks.setAdapter(categoryAdapter);
super.onPostExecute(s);
dialog.dismiss();
}
}
public class asyncTask_insertUpdatefavouriteCategories extends AsyncTask<Void, Void, Void> {
String response;
@Override
protected Void doInBackground(Void... params) {
response = InsertUpdateFavouriteCategories.insertUpdateCall(categoriesCsv);
return null;
}
@Override
protected void onPostExecute(Void s) {
Toast.makeText(context, response, Toast.LENGTH_SHORT).show();
super.onPostExecute(s);
}
}
}
解决方案
可能是旧的,可以节省一些时间.....我得到这个错误,其中服务器是 Python 和 Clinet 是 Java。
Java 客户端的第一个错误
Error while sending data over http java.io.IOException: CRLF expected at end of chunk: 79/82
java.io.IOException: CRLF expected at end of chunk: 79/82
来自 Java Clinet 的第二个错误
Error while sending data over http java.io.IOException: chunked stream ended unexpectedly
java.io.IOException: chunked stream ended unexpectedly"
通过使用分块流大小更改 ok 响应来解决这两个错误
一个有问题的
HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nTransfer-Encoding: chunked\r\nServer: Jetty(6.1.26)\r\n\r\nDE\r\n"
解决了
HTTP/1.1 200 OK\r\nContent-Length: 20000\r\nContent-Type: application/json\r\nTransfer-Encoding: chunked\r\nServer: Jetty(6.1.26)\r\n\r\n229\r\n"
注意 = nDE 替换为 n229
推荐阅读
- swift - 如何在 iOS swift 中使用 UDP 套接字流式传输音频?
- c - 字符串文字的静态持续时间
- android - Android安装后会自动删除obb扩展文件吗?
- java - 重新声明抽象方法公开的规则?
- postgresql - 使用 pg_dump 导出 postgres db 不起作用,数据库“db_name”不存在
- ibm-watson - IBM Watson Dialog 节点响应未到来
- javascript - 如何将项目推送到 Vuejs 中数据对象的数组中?Vue 似乎没有关注 .push() 方法
- c# - 将内部版本号应用于程序集的 VSTS 问题
- arrays - 如何将 PNG 生成的字节列表转换为每个像素的 RGB 值?
- neo4j - Neo4J 如何聚合和统计相同的查询结果?