我是 golang 的新手,我正在尝试编写一个函数,该函数将一个带有 post 请求的文件上传到我正在编写的机器人的电报。
我已经尝试过使用此代码,但我从电报中得到的错误是
Bad Request: there is no photo in the request.
我在网上搜索过如何做到这一点,但我发现的一切都没有帮助我解决这个问题。
func SendPostRequest (url string, filename string) []byte {
file, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
defer file.Close()
response, err := http.Post(url, "binary/octet-stream", file)
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
content, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
return content
}
Run Code Online (Sandbox Code Playgroud)
我正在调用 SendPostRequest 的函数是
func (e Engine) SendPhoto (filename string, chatId int64) APIResponse { …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 Android Studio 内部运行我的应用程序,但每次尝试时都会出现此错误:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':android:validateSigningDebug'.
> java.util.concurrent.ExecutionException:
com.android.builder.utils.SynchronizedFile$ActionExecutionException:
com.android.ide.common.signing.KeytoolException: Failed to create
keystore.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
Run Code Online (Sandbox Code Playgroud)
在线搜索解决方案并没有让我找到合适的解决方案。使用 --debug 选项运行它会给我这个结果:
15:21:41.278 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
15:21:41.278 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
15:21:41.278 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
15:21:41.278 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] …Run Code Online (Sandbox Code Playgroud)