我正在向URL发送数据,它给了我这个错误
失败!
中不支持HTTP / 1.1 505 HTTP版本
我的代码:
<?php
$pickup_time= '2016-8-20 11:11';
$city = 'Islamabad';
$pickup_address= 'aaa';
$dropoff_address = 'bbb';
$pickup_area= 'Street 1, F-8, Islamabad, Islamabad Capital Territory, Pakistan';
$drop_area= 'Karachi, Sindh, Pakistan';
$multi_areas = 'Lake View Park, Islamabad, Islamabad Capital Territory, Pakistan';
$description = 'nill';
$booking_fare = '30590';
$deadmile_distance = 'nill';
$actual_distance = '1519';
$payment_method = '1';
$pickup_area = preg_replace('/[.,]/', '', $pickup_area);// remove commas from string
$drop_area = preg_replace('/[.,]/', '', $drop_area);// remove commas from string
$multi_areas = preg_replace('/[.,]/', '', $multi_areas);// remove commas from string
$jsonData = file_get_contents("https://daewoocab-test.herokuapp.com/api/v1/customer/923331524145/booking/new?token=6ab676ddd7bf00101408ea3a27fdbb8ad22e9dcdf2faafdcd2ef0efc1509d463&booking[pickup_time]=$pickup_time&booking[city]=$city&booking[pickup_address]=$pickup_address&booking[drop_address]=$dropoff_address&booking[pickup_area]=$pickup_area&booking[drop_area]=$drop_area&booking[multi_areas]=($multi_areas)&booking[description]=$description&booking[booking_fare]=$booking_fare&booking[deadmile_distance]=$deadmile_distance&booking[actual_distance]=$actual_distance&booking[payment_method]=$payment_method");
$json = json_decode($jsonData,true);
echo $json['bookings']['id'];
?>
但是在搜索之后,我使用urlencode和我的字符串来删除空格,现在我的代码是:
$jsonData = file_get_contents("https://daewoocab-test.herokuapp.com/api/v1/customer/923331524145/booking/new?token=6ab676ddd7bf00101408ea3a27fdbb8ad22e9dcdf2faafdcd2ef0efc1509d463&booking[pickup_time]=" . urlencode($pickup_time)"&booking[city]=$city&booking[pickup_address]=$pickup_address&booking[drop_address]=$dropoff_address&booking[pickup_area]=". urlencode($pickup_area)"&booking[drop_area]=". urlencode($drop_area)"&booking[multi_areas]=(" . urlencode($multi_areas)")&booking[description]=$description&booking[booking_fare]=$booking_fare&booking[deadmile_distance]=$deadmile_distance&booking[actual_distance]=$actual_distance&booking[payment_method]=$payment_method
仍然它给我语法错误,我已经检查了100次,但没有发现任何语法错误。我在这里做错了吗?
答案 0 :(得分:0)
检查一下:
$jsonData = file_get_contents("https://daewoocab-test.herokuapp.com/api/v1/customer/923331524145/booking/new?token=6ab676ddd7bf00101408ea3a27fdbb8ad22e9dcdf2faafdcd2ef0efc1509d463&booking[pickup_time]=" . urlencode($pickup_time)."&booking[city]=$city&booking[pickup_address]=$pickup_address&booking[drop_address]=$dropoff_address&booking[pickup_area]=". urlencode($pickup_area)."&booking[drop_area]=". urlencode($drop_area)."&booking[multi_areas]=(" . urlencode($multi_areas).")&booking[description]=$description&booking[booking_fare]=$booking_fare&booking[deadmile_distance]=$deadmile_distance&booking[actual_distance]=$actual_distance&booking[payment_method]=$payment_method");
但这不是正确的方法。你应该打破它们的变量,然后将它们相互连接起来。