我有一个Wordpress表格 我想通过改装向它发送一些数据 但问题是... 在API中。我有字段名称,但没有JSONOBJECt 所以..我怎样发送数据 该API是
typeOfPin(params) {
console.log(params);
const eDiv = document.createElement('div');
// tslint:disable-next-line:no-this-assignment
const self = this;
eDiv.innerHTML =
'<select placeholder="Select" class="form-control ag-form-control">' +
'<option></option>' +
'<option value="number">Number</option>' +
'<option value="random">Random</option>' +
'</select>';
eDiv.addEventListener('change', () => {
console.log('button clicked');
self.test(event.target.value);
});
return eDiv;
}
并且这些字段位于内容JSONARRAY
中这就是我界面中的内容
[
{
"id": 1368,
"date": "2014-04-29T02:02:39",
"date_gmt": "2014-04-28T23:02:39",
"guid": {
"rendered": ""
},
"modified": "2014-04-30T14:52:32",
"modified_gmt": "2014-04-30T11:52:32",
"slug": "%d8%a7%d8%b1%d8%b3%d9%84-%d8%a7%d8%b3%d8%aa%d8%b4%d8%a7%d8%b1%d8%aa%d9%83",
"status": "publish",
"type": "page",
"link": "",
"title": {
"rendered": "ارسل استشارتك"
},
"content": {
"rendered": "<p>[vc_row][vc_column width=”1/1″]<div role=\"form\" class=\"wpcf7\" id=\"wpcf7-f1381-o1\" lang=\"ar\" dir=\"rtl\">\n<div class=\"screen-reader-response\"></div>\n<form action=\"/wp-json/wp/v2/pages#wpcf7-f1381-o1\" method=\"post\" class=\"wpcf7-form\" novalidate=\"novalidate\">\n<div style=\"display: none;\">\n<input type=\"hidden\" name=\"_wpcf7\" value=\"1381\" />\n<input type=\"hidden\" name=\"_wpcf7_version\" value=\"5.0.3\" />\n<input type=\"hidden\" name=\"_wpcf7_locale\" value=\"ar\" />\n<input type=\"hidden\" name=\"_wpcf7_unit_tag\" value=\"wpcf7-f1381-o1\" />\n<input type=\"hidden\" name=\"_wpcf7_container_post\" value=\"0\" />\n</div>\n<p><strong>هل لديك أي أسئلة تخص صحتك النفسية؟ لا تتردد وقم بمراسلتنا الآن - جميع البيانات الشخصية تخضع لسياسة الخصوصية</strong></p>\n<p>أسمك الكريم (مطلوب)<br />\n <span class=\"wpcf7-form-control-wrap your-name\"><input type=\"text\" name=\"your-name\" value=\"\" size=\"40\" class=\"wpcf7-form-control wpcf7-text wpcf7-validates-as-required\" aria-required=\"true\" aria-invalid=\"false\" /></span> </p>\n<p>بريدك الإلكتروني (مطلوب)<br />\n <span class=\"wpcf7-form-control-wrap your-email\"><input type=\"email\" name=\"your-email\" value=\"\" size=\"40\" class=\"wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email\" aria-required=\"true\" aria-invalid=\"false\" /></span> </p>\n<p>العنوان<br />\n <span class=\"wpcf7-form-control-wrap your-subject\"><input type=\"text\" name=\"your-subject\" value=\"\" size=\"40\" class=\"wpcf7-form-control wpcf7-text\" aria-invalid=\"false\" /></span> </p>\n<p>سجلك المرضى<br /><span class=\"wpcf7-form-control-wrap text-583\"><input type=\"text\" name=\"text-583\" value=\"\" size=\"40\" class=\"wpcf7-form-control wpcf7-text\" aria-invalid=\"false\" /></span> </p>\n<p>عقاقير تتناولها<br /><span class=\"wpcf7-form-control-wrap text-623\"><input type=\"text\" name=\"text-623\" value=\"\" size=\"40\" class=\"wpcf7-form-control wpcf7-text\" aria-invalid=\"false\" /></span> </p>\n<p>مدة تناول العقاقير<br /><span class=\"wpcf7-form-control-wrap text-767\"><input type=\"text\" name=\"text-767\" value=\"\" size=\"40\" class=\"wpcf7-form-control wpcf7-text\" aria-invalid=\"false\" /></span></p>\n<p>رسالتك<br /><span class=\"wpcf7-form-control-wrap your-message\"><textarea name=\"your-message\" cols=\"40\" rows=\"10\" class=\"wpcf7-form-control wpcf7-textarea\" aria-invalid=\"false\"></textarea></span> </p>\n<p><input type=\"submit\" value=\"إرسال\" class=\"wpcf7-form-control wpcf7-submit\" /></p>\n<div class=\"wpcf7-response-output wpcf7-display-none\"></div></form></div>[/vc_column][/vc_row]</p>\n",
"protected": false
},
"excerpt": {
"rendered": "<p>[vc_row][vc_column width=”1/1″][/vc_column][/vc_row]</p>\n",
"protected": false
},
"author": 1,
"featured_media": 0,
"parent": 0,
"menu_order": 0,
"comment_status": "open",
"ping_status": "open",
"template": "page-homepage-blank.php",
"meta": [],
"_links": {
"self": [
{
"href": ""
}
]
}
}
]
在我的api类中
@FormUrlEncoded
@POST("pages/1368")
Call<Person> askUs(@Field("your-name") String Name ,
@Field("your-email") String Email ,
@Field("your-message") String Message);
以及我的活动
public void sendMessage(Callback<Person> callback , String name , String email , String message){
Call<Person> person = service.askUs(name , email , message);
person.enqueue(callback);
}
及其给我的代码= 401,消息=需要授权
答案 0 :(得分:0)
首先,您应该具有表示您的JSON的Exact模型类,假设相同模型的对象已填充上述内容,则可以使用以下方法
在改造调用中,使用@Field(“ FieldNAME”)int yourVariableName,
答案 1 :(得分:0)
您应该使用@Field("FieldName)
并用@FormUrlEncoded
进行注释,以避免出现问题。
示例如下:
@FormUrlEncoded
@POST(Urls.CHNAGE_PASSWORD_URL)
Call<ChangePasswordResponse> changePassword(@Field("user_id") String
userId);