复制、修改和发送请求 POST Fiddler

Copying, modifying and sending request POST Fiddler

对不起我的英语)))

我一直在努力解决我的问题很长一段时间,但不幸的是到目前为止没有成功 (((( 我有一个POST类型的请求,我需要更改它并发送到另一个地址,并且原始请求应该更进一步到它的地址。我正在尝试与交易所合作。更重要的是,我有一个这样的请求:

https://api.binance.com/api/v3/order?symbol=CELRBTC&orderId=73902412&recvWindow=55000×tamp=1635266807744&signature=556b9c4121eb819d96a440b54661181e75ab2324a9d3b5fe0a73dd793626cb96

我需要在原始请求之后发送此请求

https://fapi/binance.com/fapi/v1/order?symbol=KEEPUSDT&side=BUY&type=MARKET&quantity=100&timeInForce=GTC&recvWindow=5000×tamp=1591702613943&signature= 3c661234138461fcc7a7d8746c6558c9842d4e10870d2ecbedf7777cad694af

此外,publicAPI在header

中传递
Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded
Accept: application/json, text/plain; q=0.9, text/html;q=0.8,
Accept-Charset: UTF-8, *;q=0.8
Accept-Encoding: gzip, deflate
X-MBX-APIKEY: YIGXAtXbQg0790CnIvKzo3oIQPmEPwiySjdQj28h0H3g87D2rwcun0kRWvh4m9J6
Host: api.binance.com

我试图在 onBeforeRequest 方法中完成所有这些工作

static function OnBeforeRequest(oSession: Session) {
   
    
if (oSession.RequestMethod == "POST" &&  oSession.uriContains("order") ) {
   
     oSession.utilDecodeResponse()
    var strBody=oSession.GetRequestBodyAsString();


       // timestamp, time ms
        
        var timestampSTART= oSession.url.IndexOf("timestamp=") + 10; 
        
        var timestampEND= oSession.url.IndexOf("&", timestampSTART);   
       
        var timestamp = oSession.url.Substring(timestampSTART, 13);
        
       
        // SYMBOL
        
        var symbolStart = oSession.url.IndexOf("symbol=")+7;
       
        var symbolend = oSession.url.IndexOf("BTC", symbolStart)+3;
   
        var symbol = oSession.url.Substring(symbolStart, symbolend-symbolStart);
        
        
       //  Signature (timestamp+SecretAPIKey=Hmac Sha256)   theoretically, it can be taken from the original request, but it is more reliable to make your own 
       var signStart = oSession.url.IndexOf("signature=")+10;
                     
       var sign = oSession.url.Substring(signStart);
        
       
        //PRICE
        
     var PriceStart = oSession.url.IndexOf("price=")+6;
     var PriceEND = oSession.url.IndexOf("&", PriceStart);
     var priceStr = oSession.url.Substring(PriceStart, PriceEND-PriceStart);
     var price = parseFloat(priceStr);
        
                                
        // Quantity
        
        var quantity = 50/ price*63000;
  
        var apiBIN =  "https://fapi.binance.com/fapi/v1/order?" ;
      
       
     //    var result = apiBIN+"symbol="+symbol+"&side=BUY&type=MARKET&quantity="+ quantity+"&timeInForce=GTC&recvWindow=5000&timestamp="+timestamp+"&signature="+sign;
            
     //    oSession.utilSetRequestBody(result)
  
     //   FiddlerApplication.oProxy.SendRequest(oSession.RequestHeaders, oSession.requestBodyBytes, null);

已经从请求中选择了必要的参数,但我不知道如何以任何方式发送它,而且我还丢失了 header 和 API 键。 另外,我要注意“签名”参数,它是使用 Hmac Sha256 算法从秘密 API 密钥和时间创建的,我也不知道如何在代码中描述它。

如果有任何帮助,我将不胜感激,并可能为实质性帮助支付一些费用。

我用C#解决了这个问题。我不知道 Fiddler 可以选择语言。从技术上讲,我已经达到了我的目标,但目前财务正在写一个错误的请求。我将单独处理。特别感谢罗伯特的帮助。

    public static void OnBeforeResponse(Session oSession)
    {
       
    
        if (oSession.HTTPMethodIs("POST") && oSession.uriContains("order")) 
        { 


              String strBody =  oSession.GetRequestBodyAsString(); 


                 //Price 

               int PriceStart = strBody.IndexOf("price=")+6;

               int PriceEND = strBody.IndexOf("&", PriceStart);

               string priceStr = strBody.Substring(PriceStart, PriceEND-PriceStart);

               float priceF = float.Parse(priceStr, System.Globalization.CultureInfo.InvariantCulture);
 

                 // SYMBOL
        
               int symbolStart = strBody.IndexOf("symbol=")+7;
       
               int symbolend = strBody.IndexOf("BTC", symbolStart);
   
               string symbol = strBody.Substring(symbolStart, symbolend-symbolStart);
        


                // Quantity
        
                int quantStart = strBody.IndexOf("quantity=")+9;
                   
                int quantend = strBody.IndexOf("&price", quantStart); 

                string quant = strBody.Substring(quantStart, quantend-quantStart);

                float quantity = float.Parse(quant, System.Globalization.CultureInfo.InvariantCulture)*2;
    

                // timestamp

                decimal timestamp = Math.Round(Convert.ToDecimal(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds), 0);

       

                //Sign

                Encoding ascii = Encoding.ASCII;

                string secretKey = "lfaeGkjitNwvyG2lqDueMhSAOzRFlzL73w5pKRCAvSy7YrxyTkvwKCcHBHj...";


                HMACSHA256 hmac = new HMACSHA256(ascii.GetBytes(secretKey));


                //   string query_string_LIMIT = "symbol="+symbol+"USDT&side=BUY&type=LIMIT&timeInForce=GTC&quantity="+quantity+"&price="+priceF+"&recvWindow=5000&timestamp="+timestamp+"&signature=";

                string result = "symbol="+symbol+"USDT&side=BUY&type=MARKET&quantity="+ quantity+"&recvWindow=5000&timestamp="+timestamp+"&signature=";
        

                String signature = BitConverter.ToString(hmac.ComputeHash(ascii.GetBytes(result))).Replace("-","");

    
   



                oSession.host="fapi.binance.com";
  
                string resultRequest = "symbol="+symbol+"USDT&side=BUY&type=MARKET&quantity="+ quantity+"&recvWindow=5000&timestamp="+timestamp+"&signature="+signature;


                

                byte[] resulByte =   System.Text.Encoding.ASCII.GetBytes(resultRequest);


                //oSession.utilReplaceInRequest("api/v3/order","fapi/v1/order?"+resultFin);

                oSession.url = oSession.url.Replace("api/v3/order", "fapi/v1/order?"+resultRequest);      


                FiddlerApplication.oProxy.SendRequest (oSession.RequestHeaders, resulByte, null);            

           }