我正在實施使用Slim框架改造,但它不工作。不能使用Slim框架實現改造
當我在使用鉻郵遞員測試我的Web API(PHP苗條代碼),那麼它是工作的罰款,並在Android的側數據通過URL,我可以看到,在logcat中也。 這是我的代碼。
<?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>
接口
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);
}
幫我guys..please
改造沒有'success'和'failure'方法..請看看在改造教程,以瞭解如何使用它 – akash93
它是改造1.9.0兄弟。它有成功和失敗的方法和我的Android代碼工作正常..只是我無法連接我的苗條代碼到android –
你應該在你的問題中包括。 1.9是超過1.5歲..無論如何你檢查是否調用'失敗'並記錄錯誤? – akash93