尝试使用Retrofit库执行POST请求。像往常一样做所有事情:
interface ApiCallHelper {
@POST("/")
void save(@Body HashMap<String, Object> params, Callback<Response> callBack);
}
然后调用以下方法:
public void menuSaveClicked(){
String url = SharedData.BASE_URL +
"api/v1/vendors/update_profile.json";
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("userId", mPrefs.getUserId());
params.put("accessToken",mPrefs.getToken());
params.put("phone", aq.id(R.id.etBusinessPhone).getText());
params.put("address", aq.id(R.id.etBusinessAddress).getText());
params.put("name", aq.id(R.id.etBusinessContactName).getText());
params.put("businessName", aq.id(R.id.etBusinessName).getText());
params.put("registrationNumber", aq.id(R.id.etBusinessRegNumber).getText());
params.put("serviceTypeIds",serviceTypeIds );
params.put("serviceAreaIds",serviceAreaIds );
params.put("website",aq.id(R.id.etBusinessWebsite).getText() );
params.put("facebook",aq.id(R.id.etBusinessFacebook).getText() );
params.put("postcode",aq.id(R.id.etBusinessPostCode).getText() );
params.put("state_id",currentState.getId() );
params.put("city_id",currentCity.getId() );
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(url)
.build();
ApiCallHelper apiCallHelper = restAdapter.create(ApiCallHelper.class);
mPD.show();
apiCallHelper.save(params, new Callback<Response>() {
@Override
public void success(Response object, Response response) {
if (mPD != null)
mPD.hide();
Toast.makeText(mContext, "Updated successfully", Toast.LENGTH_SHORT).show();
}
@Override
public void failure(RetrofitError error) {
if (mPD != null)
mPD.hide();
}
});
}
所以问题是调用在5-7分钟左右非常慢,然后我得到“java.lang.StackOverflowError:stack size 1036KB”错误。 使用AQuery尝试相同的api - 工作正常(我之所以不想使用它,是因为AQuery将所有数组作为单个String发送;我的api无法接受它)