我已经在下面发布了我的改装代码,其中有一个接口和一个mainactivity方法,其中响应主体上的方法只是接收到一个不同于任何数据的标签,并且还没有插入数据库中的数据。 XAMMP
此处在界面中我已经定义了键
无法使用改造android发送帖子请求 这是我的界面和主要活动类,如下所示 我的界面
public interface RegisterApi {
@FormUrlEncoded
@POST("/myfolder/services.php?module=jobs&action=post_new_jobs")
void insertUser(
@Field("posted_by") String posted_by,
@Field("company_name") String company_name,
@Field("position") String position,
@Field("eligiblity") String eligiblity,
@Field("experience") String experience,
@Field("interview_from_date") String interview_from_date,
@Field("interview_to_date") String interview_to_date,
@Field("interview_frm_timing") String interview_frm_timing,
@Field("interview_to_timing") String interview_to_timing,
@Field("describtion") String describtion,
@Field("skills") String skills,
@Field("interview_location") String interview_location,
@Field("interview_lat") String interview_lat,
@Field("interview_lon") String interview_lon,
@Field("contact_person") String contact_person,
@Field("contact_email") String contact_email,
@Field("contact_phone") String contact_phone,
@Field("total_vocancies") String total_vocancies,
Callback<Response> callback);
}
这里在最终按钮点击时调用此方法以发布帖子请求但不幸的是我进入了响应消息
Mainactivity
private void insertUser() {
//Here we will handle the http request to insert user to mysql db
//Creating a RestAdapter
RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(AllConstants.MAIN_URL) //Setting the Root URL
.build(); //Finally building the adapter
//Creating object for our interface
RegisterApi api = adapter.create(RegisterApi.class);
//Defining the method insertuser of our interface
api.insertUser(
AllConstants.USER_ID,
companyName.getText().toString(),
position.getText().toString(),
eligiblity.getText().toString(),
experience.getText().toString(),
interviewFrmDate.getText().toString(),
interviewToDate.getText().toString(),
interviewFromTime.getText().toString(),
interviewToTime.getText().toString(),
desc.getText().toString(),
skillsRequired.getText().toString(),
interviewLocation.getText().toString(),
String.valueOf(lat),
String.valueOf(lon),
contactperson.getText().toString(),
contactMail.getText().toString(),
contactPhone.getText().toString(),
totalVocancies.getText().toString(),
//Passing the values by getting it from editTexts
//Creating an anonymous callback
new Callback<Response>() {
@Override
public void success(Response result, Response response) {
//On success we will read the server's output using bufferedreader
//Creating a bufferedreader object
BufferedReader reader = null;
//An string to store output from the server
String output = "";
try {
//Initializing buffered reader
reader = new BufferedReader(new InputStreamReader(result.getBody().in()));
//Reading the output in the string
output = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
System.out.println("###coming exception");
}
//Displaying the output as a toast
Toast.makeText(MainActivity.this, output, Toast.LENGTH_LONG).show();
System.out.println("###coming output" + response.toString());
}
@Override
public void failure(RetrofitError error) {
//If any error occured displaying the error as toast
System.out.println("###coming failure" + error.toString());
Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_LONG).show();
}
}
);
}
答案 0 :(得分:0)
您应该将来自?module = jobs&amp; action = post_new_jobs“的参数作为带有@Query注释的方法参数传递:
@POST( “/ MyFolder文件/ services.php”) void insertUser( @Field(“posted_by”)字符串posted_by, @Query(“module”)字符串模块名称, @Query(“action”)字符串动作)