2012-07-03 39 views
0

Im有一個捲曲問題: 我從Mysql(城市名稱)獲得數據,其編碼格式爲ascii HEX(例如%DF爲ß或%DC爲ü)。 我用str_replace()轉換它們;到德國變音(ß,ü,ä,ö)。 我得到一個錯誤,當我用捲曲發送數據(城市)。(「從正確的填寫!」)CURL in PHP URL w/Umlauts

當我發送數據,而無需變音(ä,ö,ü,ß),一切都很好! 我的代碼或curl有什麼問題。我也嘗試過w/shell - 同樣的問題!

$this->url = "blah.org/?params=diesdas&city_from=Straßbourg&City_to=München"; 

$this->ckfile = tempnam("/tmp", "cookie"); 
$this->ch = curl_init(); 
curl_setopt($this->ch,CURLOPT_URL, $this->url); 
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, TRUE); 
curl_setopt($this->ch, CURLOPT_PROXY, "46.4.248.80"); 
curl_setopt($this->ch, CURLOPT_PROXYPORT, "3128"); 
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->ckfile); 
echo 'getting cookie file...'; 
$cookie = curl_exec($this->ch); 
if($cookie = false){echo 'couldn\'t get cookie!<br> '.curl_error($this->ch);}else{echo 'got cookie! omnomnom!<br>';} 

$this->ch = curl_init("blah.com/sendcookietome"); 
curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->ckfile); 
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($this->ch, CURLOPT_PROXY, "46.4.248.80"); 
curl_setopt($this->ch, CURLOPT_PROXYPORT, "3128"); 
curl_exec($this->ch); 

最好,meeeeeh!

+0

他們_應該urlencoded ....你爲什麼還原呢? – Wrikken

回答

0

我得到它的工作: wow.wtf?

此鏈接爲 'SS': blah.org/ & from_spar =Straßburg& to_spar =基爾+ HBF blah.org/ & from_spar =Köln+ HBF & to_spar =斯圖加特+ HBF

那是如何被接受的。

0

如果您在GET或POST數據中使用這些字符,則需要對這些字符進行網址編碼。不要解碼它們。

+0

當我在瀏覽器中查找「blah.org/?params=diesdas&city_from=Straßbourg&City_to=München」時 - 一切都很好!當我捲曲它 - 我得到'輸入正確的形式'。 – meeeeeh

+0

這是因爲您的瀏覽器爲您編碼的字符,保持簡單的用戶。 –

+0

當我讓變音符urlencoded我不能得到該頁面的源代碼。 此處提取Cookie的網址: http://bahn.ltur.com/index/search/?lang=de_DE&searchin=DE-SB-VI&trip_mode=trip_simple&from_spar=Stra%DFburg&to_spar=Haiger&start_datum=04.07.2012&start_time=06%3A30&end_datum = 04.07.2012&END_TIME = 16%3A30&SEA_adults = 1&trainclass_spar = 2 %DF爲SS 並得到cookie的網址: 「http://bahn.ltur.com/details」 – meeeeeh

0

使用rawurlencode()爲你的城市。

http://php.net/manual/en/function.rawurlencode.php

另外你拼錯斯特拉斯堡因爲有形式....

在您的例子:

$cityname =rawurlencode('Straßburg'); 

$url ='http://bahn.ltur.com/index/search/?mnd=de&lang=de_DE&searchin=DE-SB-VI&trip_mode=trip_simple&from_spar='.$cityname.'&to_spar=Haiger&start_datum=04.07.2012&start_time=06%3A30&end_datum=06.07.2012&end_time=16%3A42&SEA_adults=1&SEA_kids1=0&SEA_kids2=0&SEA_adult1=&SEA_adult2=&SEA_adult3=&SEA_adult4=&SEA_adult5=&SEA_kid11=&SEA_kid12=&SEA_kid13=&SEA_kid14=&SEA_kid15=&trainclass_spar=2&x=54&y=15 
'; 

//do your curl thing.. 
+0

感謝您的回答! 好吧,關鍵是,一切都在DB中正確編碼,(K%F6ln + Hbf(KölnHbf),Stra%DFburg(Straßburg)等) 當我發送請求以獲取cookie在上述url我明白'正確填寫表格'。 – meeeeeh