Что нового

ошибка Unterminated string

OlgaAdel

Новичок
Сообщения
4
Репутация
0
Добрый день, есть вот такой простенький скрипт по отправке команды на сайт. Выдает ошибку Unterminated string. Нашла что это из за того что $sPD = не в одну строчку, подскажите пожалуйста как правильно изменить скрипт что бы команда отправлялась. Спасибо

Код:
Global $hColor = 0x2962FF

_Loop()

Func _Loop()
   Local $iSearch

   Do
      $iSearch = PixelSearch (660, 159, 892, 638, $hColor)
      if @error <> 1 Then
         oHTTP ()
      EndIf
      Sleep (1000)
   Until 1 <> 1
EndFunc

Func _oHTTP

; The data to be sent
$sPD = '{
  "name": "Test",
  "secret": "vc3i425ljfdho",
  "side": "{{strategy.order.action}}",
  "symbol": "{{usd/rur}}",
  "positionSide": "{{strategy.market_position}}",
  "open": {
    "amountType": "balance",
    "amount": "33"
  },
  "sl": {
    "ofs": "1"
  },
  "tp": {
    "orders": {
      "0": {
        "ofs": "1",
        "piece": "25.0"
      },
      "1": {
        "ofs": "2.2",
        "piece": "25.0"
      },
      "2": {
        "ofs": "3.5",
        "piece": "25.0"
      },
      "3": {
        "ofs": "5",
        "piece": "25.0"
      }
    }
  }
}
'

; Creating the object
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "[URL]https://hook.finandy.com/Bkuk4Of05ZfnKjIhqdxqlUK[/URL]", False)
$oHTTP.SetRequestHeader("Content-Type", "application/json")

; Performing the Request
$oHTTP.Send($sPD)

; Download the body response if any, and get the server status response code.
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status

If $oStatusCode <> 200 then
MsgBox(4096, "Response code", $oStatusCode)
EndIf

; Saves the body response regardless of the Response code
$file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists
FileWrite($file, $oReceived)
FileClose($file)

EndFunc
 
Последнее редактирование модератором:

Medic84

Омега
Команда форума
Администратор
Сообщения
1,590
Репутация
341
Ответ. Нужно правильно переносить строки.
Можно минифицировать JSON
Код:
$sPD = '{"name":"Test","secret":"vc3i425ljfdho","side":"{{strategy.order.action}}","symbol":"{{usd/rur}}","positionSide":"{{strategy.market_position}}","open":{"amountType":"balance","amount":"33"},"sl":{"ofs":"1"},"tp":{"orders":{"0":{"ofs":"1","piece":"25.0"},"1":{"ofs":"2.2","piece":"25.0"},"2":{"ofs":"3.5","piece":"25.0"},"3":{"ofs":"5","piece":"25.0"}}}}'


Либо можно заморочиться с переносами:
Код:
$sPD = 'Первая строка' & _
'Вторая строка'
 
Автор
O

OlgaAdel

Новичок
Сообщения
4
Репутация
0
Ответ. Нужно правильно переносить строки.
Можно минифицировать JSON
Код:
$sPD = '{"name":"Test","secret":"vc3i425ljfdho","side":"{{strategy.order.action}}","symbol":"{{usd/rur}}","positionSide":"{{strategy.market_position}}","open":{"amountType":"balance","amount":"33"},"sl":{"ofs":"1"},"tp":{"orders":{"0":{"ofs":"1","piece":"25.0"},"1":{"ofs":"2.2","piece":"25.0"},"2":{"ofs":"3.5","piece":"25.0"},"3":{"ofs":"5","piece":"25.0"}}}}'


Либо можно заморочиться с переносами:
Код:
$sPD = 'Первая строка' & _
'Вторая строка'
Большое спасибо попробую
 
Верх