我正在尝试从我的服务器中保存数据。我正在使用 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);
}
}
}