我正在尝试从服务器中读取数据。我正在使用HttpClient来获取数据。但是有时无法提取数据,并且显示出在块末尾出现的称为crlf的错误。我试图更改jmeter属性following this link中的缓冲区大小,但问题尚未解决。我在下面给出我的代码。找不到解决方案。需要帮助。
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);
}
}
}
答案 0 :(得分:0)
可能很旧,可以节省一些时间..... 我在Server是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"
通过更改分块流大小的确定响应,两种错误都得到解决
一个有问题的人
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