Openlayers-服务器响应状态为401(未授权

时间:2012-09-16 14:15:44

标签: php openlayers

我在WMS上进行Plain Openlayes上的Map项目。本地服务器是Oracle Virtual Box上的Debian_x64,而Map Server是National Land Survey Finland。请求和民意调查示例可在此处http://www.maanmittauslaitos.fi/aineistot-palvelut/rajapintapalvelut/rasteriaineistojen-palvelurajapinta-wms/kayttoonotto/kyselyt-es获取。我已成功完成GetCapabilities请求并获得了XML响应。在XML响应的基础上,我尝试使用GetMap获取Map Layers。根据我现在遇到的问题的XML响应分配Map参数

  1. BoundingBox上有参数“resx and resy”,我是否需要将它们用于我正在做的事情,若然,怎么做?
  2. 我在Chrome开发者工具上监控了控制台,并回复了以下错误:
  3. Failed to load resource: the server responded with a status of 401 (Unauthorized) https://ws.nls.fi/rasteriaineistot/image?LAYERS=yleiskartta_12m&VERSION=1.1.1&FORMAT=image%2Fpng&REQUEST=GetMap&TRANSPARENT=FALSE&STYLES=light&SERVICE=WMS&SRS=EPSG%3A4326&BBOX=0,45,45,90&WIDTH=256&HEIGHT=256

    ...同时粉红色瓷砖正在装载。我使用了用户名和密码进行HTTPS基本身份验证的Php cURL代理“proxy.php”,它位于Openlayers.js,style.css和index.php所在的文件夹中。现在我分配的代理可能无法正常工作吗?或者可能有一些相同的原产地政策问题?我的用户名和密码有效。我该如何解决这个问题?如果有人提供代码示例,那将非常有用。

    我的proxy.php文件如下:

    $string = $_GET['url'];
    $urli = urldecode($string);
    $url = $urli;
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD,"user:pass");
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    $data = curl_exec($ch);
    $type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
    
    $im = imagecreatefromstring($data);
    
    if ($type == "image/jpeg") {
        header('Content-Type: image/jpeg');
        imagejpeg($im);
    } else if ($type == "image/png") {
        header('Content-Type: image/png');
        imagepng($im);
    } else if ($type == "image/gif") {
        header('Content-Type: image/gif');
        imagegif($im);
    } else if ($type == "text/xml") {
        header('Content-Type: text/xml');
        print_r($data);
    }
    
    imagedestroy($im);
    curl_close($ch);
    exit;
    
    and the index.php is as following
      function init() {
                        var map = new OpenLayers.Map('map',options)
    
                        var request = OpenLayers.Request.GET({
                                            url:"https://ws.nls.fi/rasteriaineistot/image?",
    
                                            params: {service:"WMS",
                                                     version:"1.1.1",
                                                 format:"text/xml",
                                                 request:"GetCapabilities"},
                                                     proxy: "queryboth.php?url=",
                                                     async: false,
                                                     callback: handler
    
                        } );
    
    
                        function handler(request) {
                                    console.log(request);
    
                               // alert(request.responseText);
                               // alert(request.status);
                               // alert(request.getAllResponseHeaders());
                                             }
    
    // Here I set my ProxyHost could it be some mistake here    
                     OpenLayers.ProxyHost = "proxy.php?url=";
    
                     var layer = new OpenLayers.Layer.WMS("yleiskartta",
    
                                "https://ws.nls.fi/rasteriaineistot/image?",
                                {
                                    layers: "yleiskartta_12m",
                                    version:"1.1.1",
                                    format: "image/png",
                                    request: "GetMap",
                                    transparent: false,
                                    styles:"light"  
    
    
                                },
    
                                {
    
                                   isBaseLayer: true,
                                   opacity: 1 
    
                                }
    
                        );
    
                          var options = { 
                          sphericalMercator: true,
                          projection: new OpenLayers.Projection("EPSG:3067"),
                          maxExtent: new OpenLayers.Bounds(-380688,6247443,1347312,8227443),
                                              minScale: 2121.32, 
                              maxScale: 8485.28,  
                          units: "m",
                                              numZoomLevels: 6
    
                          };
    
    
                      map.addLayers([layer]);
                      map.zoomToMaxExtent();
                                      map.addControl( new OpenLayers.Control.LayerSwitcher() );
    
                }
    

    并且xml中一个层的响应如下(抱歉,我删除了标签):

    Layer opaque="1"
    Name:yleiskartta_12m
    Title : Yleiskarttarasteri 1:12 milj
    LatLonBoundingBox minx="1.21" miny="55.57" maxx="51.93" maxy="71.79"
    BoundingBox SRS="EPSG:3067" minx="-380688" miny="6247443" maxx="1347312" maxy="8227443" resx="1500.0" resy="1500.0"
    BoundingBox SRS="EPSG:2393" minx="2619125.63" miny="6250068.42" maxx="4347827.2" maxy="8147483.65" resx="1500.0" resy="1500.0" 
    ScaleHint min="2121.32" max="8485.28"
    </Layer>
    
    </pre>
    

0 个答案:

没有答案