使用“If-None-Match”标题创建HttpWebRequest(Etag)

时间:2017-08-10 04:16:43

标签: c# json nginx httpwebrequest

我正在尝试使用normall httpwebrequest(在大多数网址上工作)从网上下载数据,但是服务器发送了我意想不到的响应,就像这样

HTTP/1.1 200 OK
Server: nginx
Date: Thu, 10 Aug 2017 03:59:39 GMT
Content-Type: application/json
Content-Length: 1984
Connection: keep-alive
Access-Control-Allow-Headers: Content-Type,Authorization,X-Requested-With,X-CSRFToken,If-None-Match-,X-API-SOURCE
Vary: Accept-Encoding, Cookie
ETag: "6f15f338d170c7f833c491beb546e4a9;gzip"
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
Set-Cookie: SPC_SI=ycl079eb0umjw270xoybjhok3hz6hp7x; expires=Fri, 11-Aug-2017 03:59:39 GMT; httponly; Max-Age=86400; Path=/
{
        "itemid": 62790979,
        "liked": false,
        "offer_count": 0,
        "videos": [],
        "rating_star": 5.187136305269734,
        "image": "6ebb860db6?????????????????????",
        "image_list": ["6ebb860db6?????????????????????"],
        "is_adult": null,
        "can_use_wholesale": false,
        "currency": "IDR",
        "rcount_with_context": 6,
        "show_free_shipping": 1,
        "estimated_days": 3,
        "show_discount": 0,
        "price_before_discount": 0,
        "cmt_count": 16,
        "is_shopee_verified": false,
        "catid": 202,
        "is_official_shop": false,
        "price_min": null,
        "rating_count": [10, 0, 0, 2, 3, 5],
        "liked_count": 13,
        "version": "6f15f338d170c7f833c491beb546e4a9",
        "coin_earn_items": [],
        "price_min_before_discount": 0,
        "cb_option": 0,
        "price": null,
        "hashtag_list": [
            "#editin??????????????",
            "#soft??????????",
            "#sof?????????",
            "#pal????????",
            "#pal????????",
            "#co??????",
            "#co???????",
            "#prog??????????",
            "#juals????????????",
            "#ins????????",
            "#fl??????",
            "#??",
            "#pal????????",
            "#u????"
        ],
        "price_max": null,
        "description": "Corel Draw Video X9 32 & 64 Bit\n2. Ulead VideoStudio v11 Plus\n3. Ulead VideoStudio v11 Plus\n4. Sony Ve?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????"
,
        "flash_sale": null,
        "models": [],
        "brand": "",
        "rcount_with_image": 1,
        "shopid": 3732962,
        "discount": null,
        "has_lowest_price_guarantee": false,
        "sold": 4,
        "price_max_before_discount": 0,
        "sub_catid": 443,
        "condition": 1,
        "name": "Packet????????????????????????",
        "wholesale_tier_list": [],
        "item_status": "no????",
        "third_catid": 6910,
        "is_pre_order": false,
        "coin_spend_cash_unit": null,
        "attributes": [],
        "stock": 118
    }

正如您所看到的,某些字段与烦人的“”相结合 我使用Fidler检查标准浏览器请求,唯一与我的请求不同的是浏览器向服务器发送“ If-None-Match - ”标头。 问题是如何填充该标题,因为我尝试从之前的请求发送etag标题但我仍然得到“”字符的响应。

希望你能理解我糟糕的语言。

这是我的代码。


    HttpWebRequest Web;
    HttpWebResponse Resp;
    StreamReader Reader;
    Web =
     (HttpWebRequest)WebRequest.Create(""https://shopee.co.id/api/v1/item_detail/?item_id=262740376&shop_id=13072340");
    Web.CookieContainer = New CookieContainer();
    Web.Method = "GET";
    Web.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240";
    Web.KeepAlive = true;
    Web.Accept = "application/json";
    Web.ContentType = "application/json; Charset=UTF-8";
    Web.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.CacheIfAvailable);
    Web.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
    Web.Headers.Add("x-requested-with", "XMLHttpRequest");
    Web.Headers.Add("x-api-source", "pc");

    Resp = (HttpWebResponse)Web.GetResponse();
    Reader = new StreamReader(Resp.GetResponseStream());
    string Res = Reader.ReadToEnd();

此代码适用于第一个5/6请求。 之后,服务器会像上面那样发送烦人的“”..

0 个答案:

没有答案