【发布时间】:2013-10-27 02:43:02
【问题描述】:
我将使用 goo.gl 来缩短 URL。我需要提出以下要求:
POST https://www.googleapis.com/urlshortener/v1/url
Content-Type: application/json
{"longUrl": "http://www.google.com/"}
我的 html:-
<form method="post" action="https://www.googleapis.com/urlshortener/v1/">
<button type="submit"> submit </button>
</form>
如何在此处添加“内容类型”和 json?
【问题讨论】:
-
您可以通过 ajax 提交表单并在那里添加 content-type 。
-
@Ghost 为什么你需要使用 ajax?
-
@Prateek 默认内容类型是“application/x-www-form-urlencoded”,现在要更改它,应该更改表单的“enctype”属性。由于发送 JSON 数据所需的问题以及我建议使用这里也适用的 ajax 请求。我不知道如何在没有 ajax 的情况下发送 JSON 数据。