国家情报局。 Post 带有 inetc 插件的俄语文本
NSIS. Post russian text with inetc plugin
我正在撰写自定义卸载程序反馈 window。有带有默认原因的单选按钮和文本字段,用户可以在其中编写自己的卸载原因。我用字符串常量和 post 替换默认原因,没有任何问题。如果我从文本字段发送英文文本,它就可以工作。但不是俄罗斯人。服务器发送错误 500,无法对我的数据进行编码。如何正确传递俄语数据?
我正在构建 Unicode 安装程序。服务器需要 UTF-8 数据。
$reason_edit_data - 来自文本字段的文本
$CB_#_State - # 单选按钮的状态 (checked/unchecked)
; **REPLACE DEFAULT REASON WITH STRING CONSTANT**
StrCpy $reason "NO_DEFAULT_REASON"
${If} $CB_1_State == ${BST_CHECKED}
StrCpy $reason "CANT_FIGURE_OUT"
${EndIf}
${If} $CB_2_State == ${BST_CHECKED}
StrCpy $reason "FAILED_WITH_PLUGINS"
${EndIf}
${If} $CB_3_State == ${BST_CHECKED}
StrCpy $reason "ERRORS_IN_APP"
${EndIf}
${If} $CB_4_State == ${BST_CHECKED}
StrCpy $reason "SUB_USE_WEB"
${EndIf}
${If} $CB_5_State == ${BST_CHECKED}
StrCpy $reason "REINSTALL_APP"
${EndIf}
; **COPY TEXTFIELD DATA TO VARIABLE. PROBLEM WITH COMMENT**
${If} $reason_edit_data == ""
StrCpy $comment "NO_EXTRA_REASON"
${Else}
StrCpy $comment "$reason_edit_data"
${EndIf}
; **POST DATA. HEADER JUST FOR EXAMPLE**
inetc::post '{ "reason": "$reason", "comment": "$comment" }' \
/TOSTACKCONV \
/SILENT \
/HEADER
"https://api.example.com/api/uninstallations" \
/END
Pop [=11=]
MessageBox MB_OK "status: [=11=]"
INetC 仅限于 UTF-16LE 和活动的 Ansi 代码页。可能会添加一个 /UTF8DATA
开关,但同时您必须将 post 数据放入文件中:
!include LogicLib.nsh
Function WriteStringAsUTF8ToFile
Exch ; File path
Exch
Exch ; NSIS string & File handle
Push [=10=]
Push ; UTF-8 string buffer
System::Call 'KERNEL32::WideCharToMultiByte(i65001,i0,wr2,i-1,p0,i0,p0,p0)i.r0'
${If} [=10=] = 0
fail_simple:
StrCpy ""
${Else}
System::Call '*(&i[=10=])p.r3'
${IfThen} P= 0 ${|} Goto fail_simple ${|}
System::Call 'KERNEL32::WideCharToMultiByte(i65001,i0,wr2,i-1,pr3,ir0,p0,p0)'
IntOp [=10=] [=10=] - 1 ; Don't write the terminator
FileOpen w
${IfThen} == "" ${|} Goto fail ${|}
System::Call 'KERNEL32::WriteFile(pr2,pr3,ir0,*i,p0)i.r0'
${IfThen} [=10=] = 0 ${|} StrCpy "" ${|}
FileClose
Goto done
fail:
StrCpy ""
done:
System::Free
${EndIf}
Pop
Pop [=10=]
Pop
Exch
FunctionEnd
Section
InitPluginsDir
Push "${U+2115}SIS" ; String to write as UTF-8
Push "$PluginsDir\data.txt"
Call WriteStringAsUTF8ToFile
Pop [=10=]
${If} [=10=] == ""
MessageBox mb_ok "Error: Unable to write post data to file!"
${Else}
inetc::post [=10=] /FILE /TOSTACK "http://example.com/post" "" /END
Pop ; "OK" on success
Pop
MessageBox mb_ok "Result: $\nResponse: "
${EndIf}
SectionEnd
我正在撰写自定义卸载程序反馈 window。有带有默认原因的单选按钮和文本字段,用户可以在其中编写自己的卸载原因。我用字符串常量和 post 替换默认原因,没有任何问题。如果我从文本字段发送英文文本,它就可以工作。但不是俄罗斯人。服务器发送错误 500,无法对我的数据进行编码。如何正确传递俄语数据?
我正在构建 Unicode 安装程序。服务器需要 UTF-8 数据。
$reason_edit_data - 来自文本字段的文本 $CB_#_State - # 单选按钮的状态 (checked/unchecked)
; **REPLACE DEFAULT REASON WITH STRING CONSTANT**
StrCpy $reason "NO_DEFAULT_REASON"
${If} $CB_1_State == ${BST_CHECKED}
StrCpy $reason "CANT_FIGURE_OUT"
${EndIf}
${If} $CB_2_State == ${BST_CHECKED}
StrCpy $reason "FAILED_WITH_PLUGINS"
${EndIf}
${If} $CB_3_State == ${BST_CHECKED}
StrCpy $reason "ERRORS_IN_APP"
${EndIf}
${If} $CB_4_State == ${BST_CHECKED}
StrCpy $reason "SUB_USE_WEB"
${EndIf}
${If} $CB_5_State == ${BST_CHECKED}
StrCpy $reason "REINSTALL_APP"
${EndIf}
; **COPY TEXTFIELD DATA TO VARIABLE. PROBLEM WITH COMMENT**
${If} $reason_edit_data == ""
StrCpy $comment "NO_EXTRA_REASON"
${Else}
StrCpy $comment "$reason_edit_data"
${EndIf}
; **POST DATA. HEADER JUST FOR EXAMPLE**
inetc::post '{ "reason": "$reason", "comment": "$comment" }' \
/TOSTACKCONV \
/SILENT \
/HEADER
"https://api.example.com/api/uninstallations" \
/END
Pop [=11=]
MessageBox MB_OK "status: [=11=]"
INetC 仅限于 UTF-16LE 和活动的 Ansi 代码页。可能会添加一个 /UTF8DATA
开关,但同时您必须将 post 数据放入文件中:
!include LogicLib.nsh
Function WriteStringAsUTF8ToFile
Exch ; File path
Exch
Exch ; NSIS string & File handle
Push [=10=]
Push ; UTF-8 string buffer
System::Call 'KERNEL32::WideCharToMultiByte(i65001,i0,wr2,i-1,p0,i0,p0,p0)i.r0'
${If} [=10=] = 0
fail_simple:
StrCpy ""
${Else}
System::Call '*(&i[=10=])p.r3'
${IfThen} P= 0 ${|} Goto fail_simple ${|}
System::Call 'KERNEL32::WideCharToMultiByte(i65001,i0,wr2,i-1,pr3,ir0,p0,p0)'
IntOp [=10=] [=10=] - 1 ; Don't write the terminator
FileOpen w
${IfThen} == "" ${|} Goto fail ${|}
System::Call 'KERNEL32::WriteFile(pr2,pr3,ir0,*i,p0)i.r0'
${IfThen} [=10=] = 0 ${|} StrCpy "" ${|}
FileClose
Goto done
fail:
StrCpy ""
done:
System::Free
${EndIf}
Pop
Pop [=10=]
Pop
Exch
FunctionEnd
Section
InitPluginsDir
Push "${U+2115}SIS" ; String to write as UTF-8
Push "$PluginsDir\data.txt"
Call WriteStringAsUTF8ToFile
Pop [=10=]
${If} [=10=] == ""
MessageBox mb_ok "Error: Unable to write post data to file!"
${Else}
inetc::post [=10=] /FILE /TOSTACK "http://example.com/post" "" /END
Pop ; "OK" on success
Pop
MessageBox mb_ok "Result: $\nResponse: "
${EndIf}
SectionEnd