我正在尝试调试与尝试的 API 调用相关的 400 错误。我是 API 新手,有人可以通过确定错误来源来帮助我吗?
这就是所做的:
我正试图从https://shop.countdown.co.nz/shop/productdetails?stockcode=281455中避开黄瓜的价格。当我用 chrome 检查元素时,黄瓜价格似乎来自以下 API:https ://shop.countdown.co.nz/api/v1/products/281455 。通过 chrome 检查 URL,我可以看到 API 响应包含以下有效负载(请参见下面的代码和屏幕截图):
{"sku":"281455","name":"fresh produce cucumbers telegraph nz","breadcrumb":{"department":{"key":"Department","value":1,"isBooleanValue":false,"name":"Fruit & Veg","productCount":0,"group":null},"aisle":{"key":"Aisle","value":104,"isBooleanValue":false,"name":"Salad Ingredients","productCount":0,"group":null},"shelf":{"key":"Shelf","value":211,"isBooleanValue":false,"name":"Cucumber","productCount":0,"group":null},"productGroup":null,"dynamicGroup":null},"images":[{"big":"https://static.countdown.co.nz/assets/product-images/zoom/9421901390013.jpg","small":"https://static.countdown.co.nz/assets/product-images/big/9421901390013.jpg"}],"unit":"Each","quantity":{"min":1.0,"max":100.0,"increment":1.0,"value":0.0},"price":{"originalPrice":4.4900,"salePrice":4.4900,"savePrice":0.00,"hasBonusPoints":false,"isClubPrice":false,"isSpecial":false,"isNew":false,"canShowOriginalPrice":true,"discount":null,"total":null,"isTargetedOffer":false,"averagePricePerSingleUnit":null},"size":{"cupPrice":0.0000,"cupMeasure":null,"packageType":"each","volumeSize":null},"alcohol":null,"healthStarRating":0,"origins":null,"description":"Cucumbers are a popular salad vegetable. While low in most nutrients cucumbers are a source of vitamin c and have a high water content. Apart from in salads, raw cucumber can also be sliced and used like crackers with dips, or in a cold soup, chopped, sauteed or juiced.","shopperNotes":"","allergens":null,"claims":null,"endorsements":null,"ingredients":null,"nutrition":null,"productNutritionMessage":null,"nutritionVerificationMessage":null,"productTags":[],"averageWeightPerUnit":0.0,"supportsBothEachAndKgPricing":false,"selectedPurchasingUnit":null,"isSuccessful":true,"rootUrl":"http://shop.countdown.co.nz","context":{"shopper":{"firstName":null,"isShopper":false,"isLoggedIn":false,"hasOnecard":null,"oneCardBalance":null,"shopperIdHash":null,"shopperScvId":null,"sessionGroups":null,"orderCount":null,"isSupplyLimitOverrideShopper":false,"isPriorityShopper":false,"hasDeliveryPass":false,"isChangingOrder":false,"changingOrderId":null},"fulfilment":{"address":"Glenfield","selectedDate":null,"selectedDateWithTZInfo":null,"startTime":null,"endTime":null,"method":"Courier","cutOffTime":null,"isSlotToday":false,"isAddressInDeliveryZone":true,"isDefaultDeliveryAddress":false,"areaId":256,"fulfilmentStoreId":9101,"perishableCode":"P","locker":null},"enabledFeatures":["ManageAddress","NewProductStamps","Search","Specials","RouteToNewShopAngularApp","PiesFiltersUI","Over18Checkbox","DetermineStoreFromAddress","ViewTrolley","HaveYouForgotten","ReviewOrder","ProjectShore","BasketOnSearchForMobile","BiteSizedRewardsHeader","ManagedServiceBar","Recipes","DeliverySubscription","DeliverySubscriptionAddressChecker","RecipesAddToTrolley","MyFavourites","SavedLists","SavedRecipes","PastOrders","UsefulLists","ContactUs","EnableLockerPickup","DeliverySubscriptionSignUp"],"shoppingListItems":[],"basketTotals":null,"advancedSettingsResponse":null},"messages":null}
这包括我所追求的价格,例如 ":{"originalPrice":4.4900,"salePrice":4.4900," 等(见截图)
然后在 chrome 中复制链接到 API URL 的 CURL 命令(参见上面的屏幕截图和下面的 curl 代码):
curl "https://shop.countdown.co.nz/api/v1/products/281455" ^
-H "authority: shop.countdown.co.nz" ^
-H "sec-ch-ua: ^\^" Not A;Brand^\^";v=^\^"99^\^", ^\^"Chromium^\^";v=^\^"90^\^", ^\^"Google Chrome^\^";v=^\^"90^\^"" ^
-H "pragma: no-cache" ^
-H "dnt: 1" ^
-H "sec-ch-ua-mobile: ?0" ^
-H "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36" ^
-H "content-type: application/json" ^
-H "accept: application/json, text/plain, */*" ^
-H "cache-control: no-cache" ^
-H "x-requested-with: OnlineShopping.WebApp" ^
-H "request-id: ^|5d71304b46d843b2937974a62b5b3630.dcf65bb2f6e34b8a" ^
-H "expires: Sat, 01 Jan 2000 00:00:00 GMT" ^
-H "sec-fetch-site: same-origin" ^
-H "sec-fetch-mode: cors" ^
-H "sec-fetch-dest: empty" ^
-H "referer: https://shop.countdown.co.nz/shop/productdetails?stockcode=281455" ^
-H "accept-language: en-GB,en-US;q=0.9,en-NZ;q=0.8,en;q=0.7" ^
-H "cookie: ai_user=IKn12^|2020-05-31T06:01:09.387Z; kampyle_userid=932d-7acf-80a9-2514-cc0e-467b-c94c-0dd6; _ga=GA1.3.752373209.1618902335; _gcl_au=1.1.432318898.1618902335; _hjid=dd4dc62f-fbf1-442c-b7fc-fa1484418358; _fbp=fb.2.1618902335815.2040961113; gig_bootstrap_3_-SfMo7rbUCn0p7mhjsDfYu8T5axQEv6QEEK9Edz5fo-fZombWKJzRgCf1-js9O2g=login_ver4; cd_user_id=178ee1947b9a5-03341fdc0862ae-c3f3568-144000-178ee1947ba682; gig_bootstrap_3_PWTq_MK-V930M4hDLpcL_qqUx224X_zPBEZ8yJeX45RHI-uKWYQC5QadqeRIfQKB=login_ver4; _gid=GA1.3.915932864.1619513575; ARRAffinity=ba6dced8d7601eacc783680b2a1cf55048b686b99e16a0b39da07afa8305314d; ARRAffinitySameSite=ba6dced8d7601eacc783680b2a1cf55048b686b99e16a0b39da07afa8305314d; dtid=2:7dgryC+6vIc4/JQ94OzZkBONH0EHDugtVauoyknOBVX6lZ1+S12z7Q+QVa0/OH1z6ElvDhpDYc+zOEKQUxIpfqItkxl9LOpYg9x0u/HQW4fo+BGjCjEc+BNRVC92eNyKgvw=; ASP.NET_SessionId=ijxjj2w2hmvq1z2ugonqk341; cw-laie=a466776e462046e6b9556a28aaa50fbf; gig_canary=false; AKA_A2=A; gig_canary_ver=12045-3-26993250; cw-arjshtsw=r0f617801ce3b4c4eb252d29559ef56b5rjduperej; kampyleUserSession=1619595516231; kampyleUserSessionsCount=12; kampyleSessionPageCounter=1; akavpau_vpshop=1619595907~id=c458adf5364d88ebb6a202e4e9aa32a6; ai_sessioncw-=KYVUk^|1619594964261^|1619595608599.01; _dc_gtm_UA-10765339-1=1; _gat_UA-10765339-1=1" ^
--compressed
当我将此 curl 脚本传递到 Insomnia 时,我收到以下“400 错误”。