<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: WinHttpRequest / URL адрес не поддерживает протокол.]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=13919&amp;type=atom" />
	<updated>2018-07-08T11:00:02Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=13919</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest / URL адрес не поддерживает протокол.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=126817#p126817" />
			<content type="html"><![CDATA[<p>Зависит от сервера.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-07-08T11:00:02Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=126817#p126817</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest / URL адрес не поддерживает протокол.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=126814#p126814" />
			<content type="html"><![CDATA[<p><strong>Malcev</strong> Отлично работает, большое спасибо! <br />В msgbox должен всегда 0 появляться?&nbsp; </p><div class="codebox"><pre><code>msgbox % HTTP.ResponseText</code></pre></div><p>И маленькая просьба, не могли бы вы с вашего ответа убрать адрес моего сайта? <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[MirchikAhtung]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=38635</uri>
			</author>
			<updated>2018-07-08T06:17:16Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=126814#p126814</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest / URL адрес не поддерживает протокол.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=126804#p126804" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>author := &quot;test&quot;
message := &quot;mess&quot;

HTTP := ComObjCreate(&quot;WinHTTP.WinHTTPRequest.5.1&quot;)
HTTP.Open(&quot;POST&quot;, &quot;http://blah-blah.myarena.ru/sendMessage.php&quot;, true)
HTTP.SetRequestHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;)
HTTP.SetRequestHeader(&quot;User-Agent&quot;, &quot;Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko)&quot;)
HTTP.SetRequestHeader(&quot;Pragma&quot;, &quot;no-cache&quot;)
HTTP.SetRequestHeader(&quot;Cache-Control&quot;, &quot;no-cache, no-store&quot;)
HTTP.SetRequestHeader(&quot;If-Modified-Since&quot;, &quot;Sat, 1 Jan 2000 00:00:00 GMT&quot;)
HTTP.Send(&quot;author=&quot; author &quot;&amp;message=&quot; message)
HTTP.WaitForResponse()
msgbox % HTTP.ResponseText</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-07-07T20:29:45Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=126804#p126804</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest / URL адрес не поддерживает протокол.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=126803#p126803" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>oForm[&quot;author&quot;].value := &quot;test&quot;
oForm[&quot;message&quot;].value := &quot;test&quot;</code></pre></div><p>Они вводят test в оба поля для ввода. ;Это и есть то, что я &quot;отправляю в браузер&quot;<br />Какую команду для кнопки использовать? Т.е oForm уже говорит само за себя, а что с кнопкой можно сделать?</p>]]></content>
			<author>
				<name><![CDATA[MirchikAhtung]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=38635</uri>
			</author>
			<updated>2018-07-07T20:16:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=126803#p126803</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest / URL адрес не поддерживает протокол.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=126802#p126802" />
			<content type="html"><![CDATA[<p>Не используйте эти функции.<br />Посмотрите, что вы отправляете в броузере и повторите в скрипте.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-07-07T20:01:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=126802#p126802</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: WinHttpRequest / URL адрес не поддерживает протокол.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=126800#p126800" />
			<content type="html"><![CDATA[<p>Привет, форумчане! Столкнулся с такой проблемой, что при выполнении следующего скрипта выскакивает ошибка с текстом, что URL адрес не поддерживает протокол. А конкретней сама кнопка.<br />Сайт стоит на хостинге и служит лишь для моего обучения. Возможно ли исправить проблему в самом коде? Не трогая сам сайт?</p><div class="codebox"><pre><code>
global oHttpRequest := ComObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)

;Загружаем документ с нужного нам URL
oHtmlDoc := documentFromURL(&quot;http://site.ru/&quot;)

;Получаем объектную модель формы
oForm := oHtmlDoc.forms(0)

;Заполняем необходимые поля
oForm[&quot;author&quot;].value := &quot;test&quot;
oForm[&quot;message&quot;].value := &quot;test&quot;

;Эмулируем отправку формы
emulateFormSubmit(oForm)

;Строим документ из полученных данных
oHtmlDoc := documentFromHTML(oHttpRequest.responseText)



;Функция эмулирующая отправку формы
emulateFormSubmit(form) {
    ;Если форма отправляется методом POST
    if (form.method = &quot;post&quot;){
        ;Проверяем метод кодирования. У нас реализован только - application/x-www-form-urlencoded
        if (form.enctype != &quot;application/x-www-form-urlencoded&quot;) {
            throw &quot;Unsupported enctype !&quot;
        }
        ;Собираем в строку имена и значения полей
        varBody := buildVarBody(form.elements)
        ;Отправляем запроса
        oHttpRequest.open(form.method, form.action, false)   ;------------------Ошибка ссылается на эту строку.
        ;Указываем заголовок типа данных, чтобы принимающая сторона поняла, что мы отправляем форму
        oHttpRequest.setRequestHeader(&quot;Content-Type&quot;, form.enctype)
        ;Передаём данные
        oHttpRequest.send(varBody)
    } 
    ;Если форма передаётся методом GET
    else if (form.method = &quot;get&quot;)
    {
        ;Получаем URL куда должны передаться данные формы
        url := form.action
        ;Если в URL присутствует символ &quot;?&quot; значит там уже идут параметры. Их мы ликвидируем.
        i := InStr(url,&quot;?&quot;)
        if (i &gt; 0 ) { 
            StringLeft url, url, i-1 
        }
        ;Собираем поля и цепляем к URL формы
        varBody := buildVarBody(form.elements)
        if (varBody &lt;&gt; &quot;&quot;) {
            url := url . &quot;?&quot; . varBody
        }
        ;Отправляем запрос
        oHttpRequest.open(&quot;GET&quot;,url,false)
        oHttpRequest.send()
    }
    else {
        throw &quot;Unsupported request method !&quot;
    }
}

;Функция сбора полей формы
buildVarBody(form) {
    ;Создаём пустой документ
    oHtmlDoc := documentFromHTML(&quot;&quot;)
    ;Включаем в нём возможность исполнения скриптов
    oHtmlDoc.designMode := &quot;off&quot;
    ;Получаем ссылку на основной объект скрипта
    oScript := oHtmlDoc.script
    ;Инициализируем JavaScript интерпретатор
    oScript.execScript(&quot;eval()&quot;)
    i := 0
    while (i &lt; form.elements.length) {
        ;Получаем элемент формы
        element := form.elements(i)
        ;Собираем строку из закодированных имён полей и их значений 
        varBody := varBody . oScript.encodeURIComponent(element.name) . &quot;=&quot; . oScript.encodeURIComponent(element.value) . &quot;&amp;&quot;
        i++
    }
    ;Отрезаем последний амперсанд на хвосте
    StringLeft varBody, varBody, StrLen(varBody)-1
    return varBody    
}

;Функция загрузки документа с указанного URL
documentFromURL(url){
    ;Формируем и отправляем HTTP запрос
    oHttpRequest.open(&quot;GET&quot;,url,false)
    oHttpRequest.send()
    ;Строим документ из полученных данных
    oHtmlDoc := documentFromHTML(oHttpRequest.responseText)
    ;Добавляем в документ тэг BASE, чтобы относительные пути преобразовать к абсолютным
    oBaseTag := oHtmlDoc.createElement(&quot;base&quot;)
    oBaseTag.href := url
    oHtmlDoc.all.tags(&quot;head&quot;)(0).appendChild(oBaseTag)
    return oHtmlDoc
}

;Функция построения документа из HTML кода
documentFromHTML(htmlCode){
    ;Создание документа
    oHtmlDoc := ComObjCreate(&quot;htmlfile&quot;)
    ;Отключаем скрипты
    oHtmlDoc.designMode := &quot;on&quot;
    ;Открытие документа
    oHtmlDoc.open(&quot;text/html&quot;)
    oHtmlDoc.write(htmlCode)
    oHtmlDoc.close()
    ;Отключение подгрузки доп. содержимого
    oHtmlDoc.execCommand(&quot;stop&quot;)
    return oHtmlDoc
}

;Функция для вывода текста в консоль
print(text){
    FileAppend, %text% `r, *
}</code></pre></div><p>Код брал тут: http://forum.script-coding.com/viewtopic.php?id=9381&amp;p=3</p>]]></content>
			<author>
				<name><![CDATA[MirchikAhtung]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=38635</uri>
			</author>
			<updated>2018-07-07T19:23:08Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=126800#p126800</id>
		</entry>
</feed>
