简体   繁体   English

改装GET请求中的字符串

[英]String in retrofit GET request

i want implement search in my app. 我想在我的应用中实施搜索。 when i log the send request with interprator i see this: 当我使用插入器记录发送请求时,我看到以下内容:

This is the URL that i want to send for English character: 这是我要发送的英文字符的URL:

https://admanroid.ir/bavand/get_near_shop_cat.php?lat=35.5088513&lng=46.172843&search="computer"

But instead of that, this URL send: 但与此相反,此URL发送:

  https://admanroid.ir/bavand/get_near_shop_cat.php?lat=35.5088513&lng=46.172843&search=computer

Its remove the Quotation mark from my search string. 它从我的搜索字符串中删除了引号。

My response returns empty results. 我的回复返回空结果。 I don't know why. 我不知道为什么 But when i send request with browser and type my string search to URL, everything works well.This problem just happened when pass string to URL 但是当我使用浏览器发送请求并将字符串搜索键入URL时,一切正常。

this is my network interface for request: 这是我的请求网络接口:

@GET("get_near_shop_cat.php")
    Observable<NearShopLocationModel> getNearShopBySearch(@Query("lat") Double lat,@Query("lng") Double lng,@Query("search") String search);

this is the observable: 这是可观察到的:

 private Observable<NearShopLocationModel> getObservableNearShopBySerach(Double lat,Double lng,String search){
        return NetworkClient.getRetrofit().create(NetworkInterface.class)
                .getNearShopBySearch(lat,lng,search)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

And this is my php code for API: 这是我的API的PHP代码:

<?php 

    //Importing the database connection 
    require_once('DBconnect.php');

    $lat = $_GET['lat'];    
    $lng = $_GET['lng'];    
    $search = $_GET["search"];  

        //SQL query to fetch data of a range 
        $sql = "SELECT id,title,imageURL1,comment,lat,lng, ( 3959 * acos( cos( radians(" . $lat . ") ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(" . $lng . ") ) + sin( radians(" . $lat . ") ) * sin( radians( lat ) ) ) ) 
        AS distance FROM shop WHERE title LIKE CONCAT('%',$search, '%') || categoryName LIKE CONCAT('%',$search, '%') HAVING distance < 5";

        //Getting result 
        $res = mysqli_query($con,$sql); 

        //Adding results to an array 
        $results = array(); 


        while($row = mysqli_fetch_array($res)){
                array_push($results, array(
                "id"=>$row['id'],
                "title"=>$row['title'],
                "imageURL1"=>$row['imageURL1'],
                "comment"=>$row['comment'],
                "lat"=>$row['lat'],
                "lng"=>$row['lng']
                )
                );

        }
        //Displaying the array in json format 
        echo json_encode(array("results"=>$results));

Send your string like this: 像这样发送您的字符串:

private Observable<NearShopLocationModel> getObservableNearShopBySerach(Double lat,Double lng,String search){
        return NetworkClient.getRetrofit().create(NetworkInterface.class)
                .getNearShopBySearch(lat,lng,"\""+search+"\"")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM