我很困惑…请帮帮我
当我提出易趣搜索请求时:
http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE[...]
在我的浏览器中,它显示一个json。我在我的webspace上复制了一个名为v1的文件中的json:
http://bloxxer.net/autentik/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=blabla;D&GLOBAL-ID=EBAY-US&RESPONSE-DATA-FORMAT=JSON&REST-PAYLOAD&keywords=fahrrad&paginationInput.entriesPerPage=3&itemFilter(0).name=MaxPrice&itemFilter(0).value=25&itemFilter(0).paramName=Currency&itemFilter(0).paramValue=EUR&itemFilter(1).name=ListingType&itemFilter(1).value(0)=AuctionWithBIN&itemFilter(1).value(1)=FixedPrice
对我的webspace的$http.get-request给了我json:

var AutApp = angular.module('AutApp', []);

AutApp.controller('ctrl', function($scope,$http) {

    $scope.search_ebay = function(keys) {
    //    var url = "http://svcs.ebay.com/services/search/FindingService/v1";
        var url = "http://bloxxer.net/autentik/v1";
            url += "?OPERATION-NAME=findItemsByKeywords";
            url += "&SERVICE-VERSION=1.0.0";
            url += "&SECURITY-APPNAME=ID"; // doesnt work on ebay without ID
            url += "&GLOBAL-ID=EBAY-US";
            url += "&RESPONSE-DATA-FORMAT=JSON";
            url += "&REST-PAYLOAD";
            url += "&keywords=fahrrad";// + keys;
            url += "&paginationInput.entriesPerPage=3";
        $http.get(url).
        success(function(data) {
            var items = data.findItemsByKeywordsResponse[0].searchResult[0].item || [];
            var html = [];
            $scope.ebay_suchergebnis='<table width="100%" border="0" cellspacing="0" cellpadding="3"><tbody>';
            for (var i = 0; i < items.length; ++i) {
                var item     = items[i];
                var title    = item.title;
                var pic      = item.galleryURL;
                var viewitem = item.viewItemURL;
                if (null != title && null != viewitem) {
                  $scope.ebay_suchergebnis+='<tr><td><a href="' + viewitem + '" target="_blank">' + '<img src="' + pic + '" border="0">' + title + '</a></td></tr>';
                }
            }
        })
        .
        error(function(data,status) {
            $scope.ebay_suchergebnis=data+"#"+status;
        });
    };
    $scope.sucheingabe="";
});

但是,如果我将$http.get-request改为svcs.ebay.com(使用我的id),它会给我“null”。
有人有主意吗?谢谢您!

最佳答案

解决方法很简单。与cors和co.无关。在服务器上绕道:

<?php
$url = "http://svcs.ebay.com/services/search/FindingService/v1";
$url .= "?OPERATION-NAME=findItemsByKeywords";
$url .= "&SERVICE-VERSION=1.0.0";
$url .= "&SECURITY-APPNAME=YOUR_ID_IN_EBAY";
$url .= "&GLOBAL-ID=EBAY-US";
$url .= "&RESPONSE-DATA-FORMAT=JSON";
$url .= "&REST-PAYLOAD";
$url .= "&".$_SERVER["QUERY_STRING"];


$json = file_get_contents($url);
echo $json;

javascript:
AutApp.controller('ctrl', function($scope,$http) {
    $scope.search_ebay = function(keys,anzahl) {

        var url='http://YourDomain.com/json_abfragen.php?keywords='+keys+"&paginationInput.entriesPerPage="+anzahl;

        $http.get(url).
        success(function(data) {
            var items = data.findItemsByKeywordsResponse[0].searchResult[0].item || [];
            var ebay_suchergebnis='<table><tr>';
            for (var i = 0; i < items.length; ++i) {
                var item = items[i];
                if (null != item.title && null != item.viewItemURL) {
                  ebay_suchergebnis+='<td><a href="' + item.viewItemURL + '" target="_blank"><img src="'+item.galleryURL+'"><br>' + items[i].title + '</a></td>';
                }
            }
            ebay_suchergebnis+='</tr></table>';
            document.getElementById('here').innerHTML=ebay_suchergebnis;
        })
        .
        error(function(data,status) {
            // errorprocessing
        });
    };
});

10-06 03:14