发送多个帖子请求的最佳方式是什么

时间:2016-12-18 16:46:30

标签: php post

我正在尝试向OPskins API发送帖子请求。 问题是我可以发送最大值。每个请求100个项目。

我有变量名称,其中包含我试图获取价格的名称。有超过100个项目名称。

$names = StatTrak™ USP-S | Kill Confirmed (Factory New),★ M9 Bayonet | Crimson Web (Field-Tested),★ Butterfly Knife | Night (Minimal Wear),★ StatTrak™ Huntsman Knife,★ M9 Bayonet | Case Hardened (Field-Tested),★ Karambit | Forest DDPAT (Minimal Wear),★ Bayonet | Damascus Steel (Factory New),StatTrak™ AK-47 | Aquamarine Revenge (Factory New),★ Butterfly Knife | Crimson Web (Field-Tested),★ Huntsman Knife | Case Hardened (Minimal Wear),StatTrak™ AK-47 | Fuel Injector (Field-Tested),★ M9 Bayonet | Night (Field-Tested),★ Huntsman Knife | Case Hardened (Field-Tested),★ Bayonet | Rust Coat (Battle-Scarred),★ Gut Knife | Doppler (Factory New),★ M9 Bayonet | Urban Masked (Field-Tested),★ Bayonet | Night (Field-Tested),★ M9 Bayonet | Scorched (Field-Tested),★ Butterfly Knife | Forest DDPAT (Field-Tested),★ Butterfly Knife | Urban Masked (Battle-Scarred),★ Butterfly Knife | Safari Mesh (Battle-Scarred),★ Bayonet | Forest DDPAT (Field-Tested),Desert Eagle | Blaze (Factory New),StatTrak™ AWP | Asiimov (Battle-Scarred),AK-47 | Vulcan (Factory New),★ Shadow Daggers | Blue Steel (Field-Tested),AK-47 | Neon Revolution (Minimal Wear),★ Bowie Knife | Scorched (Field-Tested),★ Flip Knife | Boreal Forest (Field-Tested),M4A4 | Asiimov (Field-Tested),SSG 08 | Blood in the Water (Minimal Wear),AWP | Asiimov (Battle-Scarred),AK-47 | Vulcan (Field-Tested),AWP | Hyper Beast (Field-Tested),StatTrak™ M4A1-S | Guardian (Minimal Wear),M4A4 | Desolate Space (Minimal Wear),StatTrak™ AWP | Phobos (Factory New),AK-47 | Aquamarine Revenge (Well-Worn),AWP | Redline (Well-Worn),AWP | Hyper Beast (Battle-Scarred),StatTrak™ P250 | Splash (Minimal Wear),USP-S | Orion (Factory New),USP-S | Cyrex (Factory New),AK-47 | Redline (Field-Tested),AUG | Syd Mead (Factory New),P250 | Nuclear Threat (Field-Tested),Falchion Case Key,Gamma Case Key,Chroma 2 Case Key,Operation Breakout Case Key,Glove Case Key,Gamma 2 Case Key,MAC-10 | Neon Rider (Minimal Wear),StatTrak™ XM1014 | Teclu Burner (Well-Worn),★ M9 Bayonet | Lore (Field-Tested),★ StatTrak™ Karambit | Bright Water (Field-Tested),★ StatTrak™ Karambit | Ultraviolet (Field-Tested),★ Flip Knife | Marble Fade (Factory New),★ Bowie Knife | Crimson Web (Field-Tested),★ Flip Knife | Slaughter (Field-Tested),★ Butterfly Knife | Blue Steel (Field-Tested),★ Butterfly Knife | Blue Steel (Well-Worn),★ Butterfly Knife | Blue Steel (Battle-Scarred),★ Flip Knife | Crimson Web (Field-Tested),★ Bowie Knife | Night (Field-Tested),★ Bayonet | Urban Masked (Field-Tested),★ Falchion Knife,★ Shadow Daggers | Scorched (Well-Worn),StatTrak™ AK-47 | Point Disarray (Well-Worn),M4A1-S | Mecha Industries (Minimal Wear),AK-47 | Fuel Injector (Well-Worn),StatTrak™ AK-47 | Redline (Field-Tested),AK-47 | Aquamarine Revenge (Minimal Wear),M4A4 | Royal Paladin (Minimal Wear),StatTrak™ P250 | Wingshot (Factory New),StatTrak™ Galil AR | Chatterbox (Battle-Scarred),Five-SeveN | Case Hardened (Field-Tested),AK-47 | Emerald Pinstripe (Factory New),Sticker | Bish (Holo),★ Karambit | Fade (Factory New),★ StatTrak™ Bayonet | Fade (Factory New),★ Butterfly Knife | Fade (Factory New),★ Bowie Knife | Case Hardened (Field-Tested),★ M9 Bayonet | Ultraviolet (Field-Tested),★ Falchion Knife | Slaughter (Minimal Wear),★ Bayonet | Ultraviolet (Field-Tested),★ Shadow Daggers | Crimson Web (Battle-Scarred),★ Huntsman Knife | Scorched (Field-Tested),SSG 08 | Dragonfire (Field-Tested),AWP | BOOM (Minimal Wear),StatTrak™ Music Kit | Dren, Death's Head Demolition,★ Butterfly Knife | Crimson Web (Minimal Wear),★ Huntsman Knife | Slaughter (Factory New),★ StatTrak™ Gut Knife | Tiger Tooth (Factory New),★ Bayonet | Damascus Steel (Field-Tested),★ StatTrak™ Butterfly Knife | Boreal Forest (Field-Tested),★ Flip Knife,M4A1-S | Icarus Fell (Factory New),M4A1-S | Master Piece (Minimal Wear),★ Huntsman Knife | Safari Mesh (Field-Tested),★ Flip Knife | Safari Mesh (Battle-Scarred),StatTrak™ MP7 | Nemesis (Factory New),StatTrak™ AK-47 | Frontside Misty (Battle-Scarred),Tec-9 | Isaac (Factory New),StatTrak™ Music Kit | Feed Me, High Noon,★ Falchion Knife | Urban Masked (Battle-Scarred),★ Karambit | Crimson Web (Field-Tested),★ Bayonet | Doppler (Factory New),★ Karambit | Stained (Minimal Wear),★ M9 Bayonet | Damascus Steel (Factory New),★ Bowie Knife | Night (Minimal Wear),AK-47 | Fire Serpent (Battle-Scarred),★ Bowie Knife | Crimson Web (Battle-Scarred),StatTrak™ AK-47 | Jaguar (Minimal Wear),★ Butterfly Knife | Scorched (Field-Tested),★ Bowie Knife | Forest DDPAT (Field-Tested),USP-S | Kill Confirmed (Field-Tested),StatTrak™ USP-S | Caiman (Factory New),StatTrak™ AWP | Lightning Strike (Factory New),★ Bayonet | Fade (Factory New),★ StatTrak™ M9 Bayonet | Damascus Steel (Field-Tested),★ Bayonet | Bright Water (Field-Tested),★ Falchion Knife | Forest DDPAT (Field-Tested),USP-S | Kill Confirmed (Minimal Wear),Chroma 3 Case Key,Operation Wildfire Case Key,StatTrak™ Dual Berettas | Marina (Minimal Wear),★ Flip Knife | Crimson Web (Minimal Wear),StatTrak™ AWP | BOOM (Minimal Wear),★ Gut Knife | Slaughter (Minimal Wear),★ Bowie Knife | Urban Masked (Minimal Wear),★ Falchion Knife | Blue Steel (Minimal Wear),★ Gut Knife | Case Hardened (Well-Worn),★ Shadow Daggers | Night (Field-Tested),★ Bowie Knife | Safari Mesh (Field-Tested),StatTrak™ Sawed-Off | Limelight (Factory New),★ Butterfly Knife | Night (Field-Tested),StatTrak™ AK-47 | Frontside Misty (Factory New),★ Huntsman Knife | Night (Field-Tested),StatTrak™ UMP-45 | Primal Saber (Factory New),★ Flip Knife | Urban Masked (Minimal Wear),AWP | Graphite (Factory New),StatTrak™ Tec-9 | Blue Titanium (Factory New),★ Bowie Knife | Slaughter (Factory New),★ Shadow Daggers | Slaughter (Minimal Wear),★ Gut Knife | Freehand (Field-Tested),StatTrak™ M4A1-S | Cyrex (Field-Tested),★ Karambit | Doppler (Factory New),StatTrak™ M4A1-S | Hyper Beast (Factory New),StatTrak™ AK-47 | Vulcan (Field-Tested),★ Bayonet | Scorched (Field-Tested),StatTrak™ AWP | Redline (Minimal Wear),AWP | Hyper Beast (Factory New),M4A1-S | Mecha Industries (Factory New),AK-47 | Wasteland Rebel (Battle-Scarred),StatTrak™ M4A4 | Zirka (Minimal Wear),StatTrak™ CZ75-Auto | The Fuschia Is Now (Minimal Wear),Huntsman Case Key,Chroma Case Key,★ Flip Knife | Slaughter (Factory New),★ Huntsman Knife | Slaughter (Field-Tested),Desert Eagle | Golden Koi (Factory New),AK-47 | Jaguar (Battle-Scarred),StatTrak™ P90 | Trigon (Battle-Scarred),StatTrak™ Desert Eagle | Directive (Field-Tested),★ Bowie Knife | Fade (Factory New),★ Flip Knife | Tiger Tooth (Factory New),★ M9 Bayonet | Safari Mesh (Field-Tested),★ Flip Knife | Ultraviolet (Field-Tested),M4A1-S | Basilisk (Factory New),StatTrak™ M4A4 | Bullet Rain (Factory New),★ Flip Knife | Safari Mesh (Field-Tested),★ Bowie Knife | Blue Steel (Field-Tested),AK-47 | Case Hardened (Minimal Wear),StatTrak™ M4A4 | Desert-Strike (Field-Tested),Operation Phoenix Case Key,★ Bayonet | Damascus Steel (Well-Worn),★ Flip Knife | Damascus Steel (Factory New),StatTrak™ Glock-18 | Dragon Tattoo (Factory New),StatTrak™ MP7 | Ocean Foam (Factory New),USP-S | Business Class (Field-Tested),★ Flip Knife | Fade (Factory New),★ Falchion Knife | Night (Minimal Wear),M4A1-S | Master Piece (Field-Tested),AK-47 | Case Hardened (Field-Tested),G3SG1 | Chronos (Factory New),CZ75-Auto | The Fuschia Is Now (Factory New),★ StatTrak™ Bayonet | Scorched (Field-Tested),StatTrak™ AK-47 | Fire Serpent (Field-Tested),★ Flip Knife | Doppler (Factory New),M4A1-S | Hot Rod (Factory New),M4A4 | Radiation Hazard (Well-Worn),M4A1-S | Master Piece (Battle-Scarred),P250 | Mehndi (Well-Worn),eSports Key,★ Karambit | Bright Water (Minimal Wear),StatTrak™ AK-47 | Case Hardened (Field-Tested),★ Gut Knife | Damascus Steel (Field-Tested),★ Bayonet | Marble Fade (Factory New),★ M9 Bayonet | Bright Water (Field-Tested),★ Falchion Knife | Scorched (Well-Worn),Five-SeveN | Case Hardened (Well-Worn),

我可以通过这种方式发送100件物品

$postdata2 = http_build_query(
                                array(
                                    'key' => 'febfdssdfe5a1cc9c7cb32fa0a54',
                                    'appid' => '730',
                                    'contextid' => '2',
                                    'names' => $names
                                )
                            );

                            $opts2 = array('http' =>
                                array(
                                    'method'  => 'POST',
                                    'header'  => 'Content-type: application/x-www-form-urlencoded',
                                    'content' => $postdata2
                                )
                            );

                            $context2  = stream_context_create($opts2);
                            $json_op = file_get_contents('https://opskins.com/api/user_api.php?request=GetLowestSalePrices', false, $context2);

我可以计算我在$ names中有多少个名字(项目)以及我需要发送多少个请求,但是发送它们并在1个json对象中获取结果的最佳方法是什么?

1 个答案:

答案 0 :(得分:0)

您可以考虑将array_chunk()explode()一起使用并循环请求,然后合并到结果中。

例如:

$names = "StatTrak™ USP-S | Kill Confirmed (Factory New),★ M9 Bayonet | Crimson Web (Field-Tested),★ Butterfly Knife | Night (Minimal Wear),★ StatTrak™ Huntsman Knife,★ M9 Bayonet | Case Hardened (Field-Tested),★ Karambit | Forest DDPAT (Minimal Wear),★ Bayonet | Damascus Steel (Factory New),StatTrak™ AK-47 | Aquamarine Revenge (Factory New),★ Butterfly Knife | Crimson Web (Field-Tested),★ Huntsman Knife | Case Hardened (Minimal Wear),StatTrak™ AK-47 | Fuel Injector (Field-Tested),★ M9 Bayonet | Night (Field-Tested),★ Huntsman Knife | Case Hardened (Field-Tested),★ Bayonet | Rust Coat (Battle-Scarred),★ Gut Knife | Doppler (Factory New),★ M9 Bayonet | Urban Masked (Field-Tested),★ Bayonet | Night (Field-Tested),★ M9 Bayonet | Scorched (Field-Tested),★ Butterfly Knife | Forest DDPAT (Field-Tested),★ Butterfly Knife | Urban Masked (Battle-Scarred),★ Butterfly Knife | Safari Mesh (Battle-Scarred),★ Bayonet | Forest DDPAT (Field-Tested),Desert Eagle | Blaze (Factory New),StatTrak™ AWP | Asiimov (Battle-Scarred),AK-47 | Vulcan (Factory New),★ Shadow Daggers | Blue Steel (Field-Tested),AK-47 | Neon Revolution (Minimal Wear)";
$names = explode(',', $names);
$nameChunks = array_chunk($names, 100);
$results = [];
foreach($nameChunks as $nameChunk) {
    $postData2 = http_build_query([
        'key' => 'febfdssdfe5a1cc9c7cb32fa0a54',
        'appid' => '730',
        'contextid' => '2',
        'names' => $nameChunk
    ]);

    $context2  = stream_context_create([
        'http' => [
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => $postData2
        ]
    ]);

    $json_op = json_decode(file_get_contents('https://opskins.com/api/user_api.php?request=GetLowestSalePrices', false, $context2), true);
    $results = array_merge($results, $json_op['result']);
}

结果如下:

array(3) {
    ["appid"]=> int(730)
    ["contextid"]=> string(1) "2"
    ["items"]=> NULL
}

在进一步检查时,看起来此处使用的API方法已过时。我认为你想要的是IPricing/GetAllLowestListPrices/v1,它不需要请求特定的项目。这里的文档:https://opskins.com/kb/api-ipricing#method-getalllowestlistprices-v1