我正在尝试使用 HTTP POST 请求执行 PHP 脚本。这是我用来执行 POST 的 Android 代码。
String url = "xxx";
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
// set params
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("toEmail", toEmail));
pairs.add(new BasicNameValuePair("toName", toName));
pairs.add(new BasicNameValuePair("fromEmail", email));
pairs.add(new BasicNameValuePair("fromName", achternaam));
pairs.add(new BasicNameValuePair("type", "Manual"));
pairs.add(new BasicNameValuePair("job", jobId));
pairs.add(new BasicNameValuePair("firstname", voornaam));
pairs.add(new BasicNameValuePair("lastname", achternaam));
pairs.add(new BasicNameValuePair("phone", tel));
pairs.add(new BasicNameValuePair("email", email));
pairs.add(new BasicNameValuePair("comment", opmerkingen));
HttpResponse response;
post.setEntity(new UrlEncodedFormEntity(pairs));
response = client.execute(post);
当我调试此代码并进入响应本身时,BasicStatusLine 是:HTTP/1.1 200 OK。哪个应该表明 PHP 脚本已正确执行?好吧,脚本应该做一个mailto。这是 PHP 脚本:
<?php
require_once('mail.php');
require_once('Job.php');
if (isset($_POST['toEmail'])) {
sql_insert(array('content' => var_export($_POST, true), 'email' =>
$_POST['toEmail'], 'type' => $_POST['type']), 'Apply');
} else {
sql_insert(array('content' => var_export($_POST, true), 'email' => 'no email',
'type' => $_POST['type']), 'Apply');
}
if (isset($_POST['type']) && $_POST['type'] == 'LinkedIn' && isset($_POST['job'])) {
$to = 'HARDCODEDEMAIL'
$from = array('email' => '', 'name' => '');
$firstname = '';
$lastname = '';
$profile = '';
$img = '';
$headline = '';
$location = '';
$industry = '';
$current = array();
$past = array();
$education = array();
$recommendations = 0;
$phone = '';
$address = '';
$twitter = array();
if (isset($_POST['toEmail'])) {
$to['email'] = $_POST['toEmail'];
}
if (isset($_POST['toName'])) {
$to['name'] = $_POST['toName'];
}
if (isset($_POST['fromEmail'])) {
$from['email'] = $_POST['fromEmail'];
}
if (isset($_POST['fromName'])) {
$from['name'] = $_POST['fromName'];
}
$job = new Job();
$job->init($_POST['job']);
if (isset($_POST['firstname'])) {
$firstname = $_POST['firstname'];
}
if (isset($_POST['lastname'])) {
$lastname = $_POST['lastname'];
}
if (isset($_POST['profile'])) {
$profile = $_POST['profile'];
}
if (isset($_POST['img'])) {
$img = $_POST['img'];
}
if (isset($_POST['headline'])) {
$headline = $_POST['headline'];
}
if (isset($_POST['location'])) {
$location = $_POST['location'];
}
if (isset($_POST['industry'])) {
$industry = $_POST['industry'];
}
if (isset($_POST['current'])) {
$currentString = $_POST['current'];
$positions = explode("*_*", $currentString);
foreach ($positions as $positionString) {
$items = explode("**", $positionString);
if (count($items) > 0) {
$position = array('title' => '', 'url' => '', 'company' => '');
$position['title'] = $items[0];
if (count($items) > 1) {
$position['company'] = $items[1];
if (count($items) > 2) {
$position['url'] = 'http://www.linkedin.com/company/' . $items[2];
}
}
$current[] = $position;
}
}
}
if (isset($_POST['past'])) {
$pastString = $_POST['past'];
$positions = explode("*_*", $pastString);
foreach ($positions as $positionString) {
$items = explode("**", $positionString);
if (count($items) > 0) {
$position = array('title' => '', 'url' => '', 'company' => '');
$position['title'] = $items[0];
if (count($items) > 1) {
$position['company'] = $items[1];
if (count($items) > 2) {
$position['url'] = 'http://www.linkedin.com/company/' . $items[2];
}
}
$past[] = $position;
}
}
}
if (isset($_POST['education'])) {
$educationsString = $_POST['education'];
$educations = explode("*_*", $educationsString);
foreach ($educations as $edu) {
$education[] = $edu;
}
}
if (isset($_POST['recommendations'])) {
$recommendations = $_POST['recommendations'];
}
if (isset($_POST['phone'])) {
$phone = $_POST['phone'];
}
if (isset($_POST['address'])) {
$address = $_POST['address'];
}
if (isset($_POST['twitter'])) {
$twitterString = $_POST['twitter'];
$accounts = explode("*_*", $twitterString);
foreach ($accounts as $account) {
$twitter[] = $account;
}
}
$mail = new Email();
$mail->linkedIn($to, $from, $job, $firstname, $lastname, $profile, $img,
$headline, $location, $industry, $current, $past, $education, $recommendations,
$phone, $address, $twitter);
} else if (isset($_POST['type']) && $_POST['type'] == 'Manual' &&
isset($_POST['job'])) {
$to = array('email' => '', 'name' => '');
$from = array('email' => '', 'name' => '');
$firstname = '';
$lastname = '';
$phone = '';
$email = '';
$comment = '';
if (isset($_POST['toEmail'])) {
$to['email'] = $_POST['toEmail'];
}
if (isset($_POST['toName'])) {
$to['name'] = $_POST['toName'];
}
if (isset($_POST['fromEmail'])) {
$from['email'] = $_POST['fromEmail'];
}
if (isset($_POST['fromName'])) {
$from['name'] = $_POST['fromName'];
}
$job = new Job();
$job->init($_POST['job']);
if (isset($_POST['firstname'])) {
$firstname = $_POST['firstname'];
}
if (isset($_POST['lastname'])) {
$lastname = $_POST['lastname'];
}
if (isset($_POST['phone'])) {
$phone = $_POST['phone'];
}
if (isset($_POST['email'])) {
$email = $_POST['email'];
}
if (isset($_POST['comment'])) {
$comment = $_POST['comment'];
}
$mail = new Email();
var_dump($to);
$mail->normal('HARDCODEDEMAIL', $from, $job, $firstname, $lastname, $phone, $email, $comment);
出于测试目的,我将电子邮件地址硬编码到 PHP 代码中。有人能在这里发现我的错误吗?如果没有:是否有技术可以用这个特定的 HTTP 帖子测试 php 脚本?