以下是我集成的代码片段,用于将图像上传到WAMP服务器并从服务器获取响应。
private void uploadImage() {
String name = "image";
String path = p;
try {
String uploadid = UUID.randomUUID().toString();
new MultipartUploadRequest(this, uploadid, UPLOAD_URL)
.addFileToUpload(path, "image")
.addParameter("name", name)
.setNotificationConfig(new UploadNotificationConfig())
.setMaxRetries(2)
.startUpload();
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(second.this, " Before the SHOW msg" , Toast.LENGTH_SHORT).show();
try{
new Response.Listener<String>() {
@Override
public void onResponse(String s) {
Toast.makeText(second.this, s , Toast.LENGTH_SHORT).show();
CharSequence cs = s;
inf.setText(cs);
}
};
}
catch(Exception e) {
e.printStackTrace();
}
}
onResponse方法中的代码无效,因为其中的toast消息未在移动设备中显示。我期待php中的echo消息被分配给字符串&#39; s&#39;在onResponse中,反过来消息在EditText(inf)上。