我使用PHP cURL与Rest API进行通信。大多数功能是使用X-Ephemeral-Tokens执行的,但是不幸的是,它们不允许通过这些功能给予删除权限,因此我必须实现一个通过HTTP Basic Authentication进行删除的功能。
我遇到的麻烦是测试帐户的密码是一个随机字符串,包括多个特殊字符(其中一些使用双引号)。通过将username:password组合用单引号引起来,我使用了普通的cURL二进制文件来处理请求,'但是我不确定如何将其转换为PHP。相关代码段如下。
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/json",
"Content-Type: application/json"));
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $uname . ":" . $pass);
curl_setopt($curl, CURLOPT_URL, "https://cloud.ravellosystems.com/api/v1/applications/" . $appid);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
$result = curl_exec($curl);
Run Code Online (Sandbox Code Playgroud)
我已经尝试过使用引号和URL编码进行各种组合,但仍然得到一个响应代码,表明身份验证不正确。
这是基于API文档显示的使用普通cURL的示例HTTP请求(略有修改)
curl -v -X DELETE -H "Content-Type: application/json" -H "Accept: application/json" --user ravello@ravello.com:password https://cloud.ravellosystems.com/api/v1/applications/414244
Run Code Online (Sandbox Code Playgroud)
任何有关如何解决此问题的建议,我们将不胜感激。
我正在尝试弹出一个对话框,显示有关ListView中条目的更多信息.ListView生成正常,对话框的所有变量都初始化正常,但是当我尝试将相关描述写入EditText框时,抛出NullPointerException.有任何想法吗?
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
//TODO Add code for action performed on item click here
// i.e. open dialogue showing details
// Custom dialog box
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.view_dialog);
dialog.setTitle("Description: " + savedSubjects[position]);
// set custom dialog components
EditText descriptionOutput = (EditText) findViewById(R.id.dialogText);
String descToWrite = savedDescriptions[position]; // I created this in case calling from the array was the problem. In the trace this variable is correctly set.
descriptionOutput.setText(descToWrite); …Run Code Online (Sandbox Code Playgroud) android listview dialog nullpointerexception android-edittext
我遇到了这段代码的问题.第6行的if语句在执行期间被忽略.我已经逐步完成了代码,变量文件[position]的值是"subjects.dat".但是,它正在跳过此步骤并转到相关的else语句.任何想法为什么??
dialogButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (markComplete.isChecked()) {
String toDelete;
String[] files = fileList();
if (files[position] == "subjects.dat") { //the error occurs at this line
toDelete = files[position + 1];
boolean deleted = deleteFile(toDelete);
if (deleted) {
dialog.dismiss();
} else {
// Do nothing
}
} else {
toDelete = files[position];
boolean deleted = deleteFile(toDelete);
if (deleted) {
dialog.dismiss();
} else {
//Do nothing
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!