मैं IBM worklight के साथ घूम रहा हूं, और Google places API से कुछ डेटा खाने के लिए एडाप्टर बनाने की कोशिश कर रहा हूं।वर्कलाइट का उपयोग कर सर्वरसाइड जावास्क्रिप्ट के साथ HTTPS अनुरोध कैसे करें?
https://maps.googleapis.com/maps/api/place/search/json?key=AIzaSyCTlPms1pvhzeoRrBao5qW-DJMI_CWcbAM&location=52.0700,1.1400&radius=10000&sensor=false&name=coffee
इस URL निष्पादित एक ब्राउज़र में ठीक काम करता है, और कुछ अच्छा JSON कि मैं Worklight के माध्यम से प्राप्त करने के लिए कोशिश कर रहा हूँ प्रदर्शित करता है:
मैं इस URL को कॉल करना चाहते हैं।
Worklight एडेप्टर जावास्क्रिप्ट में बनाए गए हैं, यह क्या मैं अब तक है:
function getCoffeeHouses() {
var input = {
method : 'get',
returnedContentType : 'json',
path : 'maps/api/place/search/json',
parameters : {
'key' : 'AIzaSyCTlPms1pvhzeoRrBao5qW-DJMI_CWcbAM',
'location' : '52.0700,1.1400',
'radius' : '10000',
'sensor' : 'false',
'name' : 'coffee'
}
};
var response = WL.Server.invokeHttp(input);
// Extract latitude and longitude from the response.
var type = typeof response;
if ("object" == type) {
if (true == response["isSuccessful"]) {
// Return JSON object with lat and lng.
return response["results"];
}
else {
// Returning null. Web request was not successful.
return null;
}
}
else {
// Returning null. Response is not an object.
return null;
}
}
और जब मैं ऊपर का परीक्षण इस परिणाम है कि मैं कंसोल में मिलता है,:
Failed to parse JSON string
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 404 (Not Found)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}
</style>
<a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
<p><b>404.</b> <ins>That’s an error.</ins>
<p>The requested URL <code>/maps/api/place/search/json?key=AIzaSyCTlPms1pvhzeoRrBao5qW-DJMI_CWcbAM&location=52.0700%2C1.1400&radius=10000&sensor=false&name=coffee</code> was not found on this server. <ins>That’s all we know.</ins>
Caused by: java.io.IOException: Unexpected character '<' on line 1, column 1
[2012-07-23 11:08:57] An error occurred while invoking procedure CoffeeFinder/getCoffeeHouses parameters: {
"arr": [
]
}
null
Caused by: null
मुझे लगता है कि यह शायद इसलिए हुआ है क्योंकि एडाप्टर HTTP के रूप में अनुरोध कर रहा है, जबकि यह HTTPS का उपयोग करना चाहिए।
यदि मैं किसी ब्राउज़र में HTTP का उपयोग करने का अनुरोध बदलता हूं, तो यह समान परिणाम प्रदर्शित करता है।
प्रश्न: क्या मैं उपर्युक्त जावास्क्रिप्ट को बदलकर एक HTTPS अनुरोध कर सकता हूं, या क्या मैं वर्कलाइट एडाप्टर को गलतफहमी कर रहा हूं?
मैं भी एक ऐसी ही समस्या है .. मैंने सभी सभी सामग्री प्रकारों का उल्लेख किया है लेकिन यह बिल्कुल काम नहीं कर रहा है .. – Sarath
त्रुटि विवरण है "सर्वर ने इस अनुरोध को अस्वीकार कर दिया क्योंकि अनुरोध इकाई में है अनुरोधित विधि (असमर्थित मीडिया प्रकार) के लिए अनुरोधित संसाधन द्वारा समर्थित प्रारूप नहीं है .... "मैंने सामग्री-प्रकार निर्दिष्ट किया है: 'एप्लिकेशन/जेसन' .. लेकिन फिर भी समस्या जारी है .. – Sarath