Slim Frameworkを使用してRetrofitを実装していますが、機能しません。Slim frameworkを使用してRetrofitを実装することができません
クロムの郵便配達員を使用してWeb API(PHPスリムコード)をテストしているとき、正常に動作しています。Android側のデータがURLを通過しています。 ここに私のコードです。ここで
<?php
$app->post('/directorder',function($request) {
require_once('dbconnect.php');
$query = "INSERT INTO direct_order (d_name,d_contact,d_address) values (?,?,?)";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("sss",$a,$b,$c);
$a = $request->getParsedBody()['d_name'];
$b = $request->getParsedBody()['d_contact'];
$c = $request->getParsedBody()['d_address'];
if ($stmt->execute()) {
echo json_encode("success");
} else {
echo json_encode("fail");
}
});
?>
は私のAndroid側のコード
活動です
public class DirectOrderActivity extends AppCompatActivity {
EditText name,contact,address;
Button buttonUpload;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_direct_order);
name = (EditText) findViewById(R.id.input_name);
address = (EditText) findViewById(R.id.input_address);
contact = (EditText) findViewById(R.id.input_contact);
buttonUpload = (Button) findViewById(R.id.btn_directorder);
buttonUpload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String ename=name.getText().toString();
String eaddress=address.getText().toString();
String econtact=contact.getText().toString();
RestAdapter adapterCity = new RestAdapter.Builder()
.setEndpoint(Base.Base_Url)
.setLogLevel(RestAdapter.LogLevel.FULL)
.build();
UserInterface services = adapterCity.create(UserInterface.class);
services.directorder(ename , econtact,eaddress , new Callback<String>() {
@Override
public void success(String s, Response response) {
Toast.makeText(getApplicationContext(), "Order Successfully", Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext() , MainActivity.class);
startActivity(intent);
}
@Override
public void failure(RetrofitError error) {
}
});
}
});
}
}
xmlファイル
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.anthesis.benchmarkayurveda.NewVisitActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="24dp"
android:paddingRight="24dp">
<!-- Email Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<EditText android:id="@+id/input_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="Name of Docotr/Medical Shop" />
</android.support.design.widget.TextInputLayout>
<!-- Email Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<EditText android:id="@+id/input_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="Address" />
</android.support.design.widget.TextInputLayout>
<!-- Email Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<EditText android:id="@+id/input_contact"
android:layout_below="@+id/input_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:hint="Contact"
android:lines="1"/>
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_directorder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:layout_marginLeft="20dp"
android:padding="12dp"
android:background="@color/colorPrimary"
android:text="Save and Place Order"/>
</LinearLayout>
</RelativeLayout>
INTERFACE
public interface UserInterface {
@POST("/directorder")
public void directorder(@Query("d_name") String ename, @Query("d_contact") String eaddress, @Query("d_address") String econtact, retrofit.Callback<String> response);
}
Help me guys..please
Retrofitには、「成功」と「失敗」のメソッドがありません。使用方法を理解するために、改装に関するチュートリアルをご覧ください。 – akash93
1.9.0 brood .. retrofitです。成功と失敗のメソッドとAndroidのコードちょうど私はアンドロイドに私のスリムコードを接続することができません –
あなたはあなたの質問に含める必要があります。 1.9は1.5歳以上です..とにかく、 'failure'が呼び出されてエラーが記録されたかどうかチェックしましたか? – akash93