请求协助:将指定HTTP请求转换为cURL与PowerShell命令
Slack API请求转cURL和PowerShell命令修正
原始HTTP请求
POST /api/users.profile.set Host: slack.com Content-type: application/json; charset=utf-8 Authorization: bearer_token { "profile": { "status_text": "Eating some french fries from the frituur", "status_emoji": ":fries:" } }
修正后的cURL命令
你原命令中status_emoji的双引号未转义,存在语法错误,同时补充了与原始请求一致的字符编码头,修正后命令如下:
curl 'https://slack.com/api/users.profile.set' \ --header 'Authorization: bearer_token' \ --header 'Content-Type: application/json; charset=utf-8' \ --data-raw "{ \"profile\": { \"status_text\": \"Eating some french fries from the frituur\", \"status_emoji\": \":fries:\" } }"
- 需将
bearer_token替换为你的实际Slack API令牌 - 确保所有双引号转义正确,避免JSON格式报错
修正后的PowerShell命令
你原命令缺少请求体参数,需添加JSON格式的请求内容,修正后命令如下:
# 构造请求体并转为JSON格式 $requestBody = @{ profile = @{ status_text = "Eating some french fries from the frituur" status_emoji = ":fries:" } } | ConvertTo-Json Invoke-WebRequest -Headers @{"Authorization" = "bearer_token"} ` -Method POST ` -Uri "https://slack.com/api/users.profile.set" ` -ContentType "application/json; charset=utf-8" ` -Body $requestBody
- 用哈希表转JSON的方式避免手动转义双引号的繁琐
- 替换
bearer_token为你的实际API令牌
内容的提问来源于stack exchange,提问作者shadowz1337
相关产品推荐
相关产品推荐

