2014-02-19 41 views
0

歡迎大家! 我在這裏是新來的,我正在尋找Prestashop webservice和Android的解決方案。 我必須編寫一個android應用程序,它解析來自prestashop web服務的XML,我不知道該怎麼做。 Offcourse,我在prestashop中設置了web服務,它生成一個xml。最後,我有一個xml:從Prestashop webservice解析Android中的XML

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> 
    <api shop_name="myShop"> 
    <addresses xlink:href="https://myshop.pl/api/addresses" get="true" put="false" post="true" delete="false" head="true"> 
     <description xlink:href="https://myshop.pl/api/addresses" get="true" put="false" post="true" delete="false" head="true">The Customer, Manufacturer and Customer addresses</description> 
     <schema xlink:href="https://myshop.pl/api/addresses?schema=blank" type="blank"/> 
     <schema xlink:href="https://myshop.pl/api/addresses?schema=synopsis" type="synopsis"/> 
    </addresses> 
    </api> 
</prestashop> 

我嘗試使用此tutorial來解析上面的XML,但問題是java.io.FileNotFoundException在爲InputStream stream = conn.getInputStream()行。

難道有誰能幫助我?

對不起,我的英文,如果有任何錯誤的文字。

+0

檢查康恩它首先是否爲空或不是? – Naren

+0

您是否可以從外部訪問您的服務url(例如,在瀏覽器中) – bachr

回答

0

我解決了這個問題,通過增加前connect()方法這一行:

String userpassword = "key_authentication"+":"+""; // empty password should not be missed 
String encoded = new String(Base64.encode(userpassword.getBytes(), Base64.DEFAULT)); 
connection.setRequestProperty("Authorization", "Basic " + encoded); 
+0

如果您只傳遞'username'參數並錯過傳遞PrestaShop API的空密碼,它將返回401 http錯誤代碼,這意味着未經授權。你可以看看http://stackoverflow.com/questions/22404778/prestashop-and-web-servicerestful-httpurlconnection-bufferedreader – VSB