发布请求以包含“内容类型"和 JSON [英] Post request to include 'Content-Type' and JSON

查看:27
本文介绍了发布请求以包含“内容类型"和 JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用 goo.gl 来缩短 URL.我需要提出以下请求:

I'm to work with goo.gl for URL shortening. I need to make the following request:

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?

how do i add the 'content-type' and json here?

推荐答案

浏览器不支持 JSON 作为表单提交的媒体类型(支持的类型是 在规范中列出).

Browsers do not support JSON as a media type for form submissions (the supported types are listed in the spec).

从网页发出此类请求的唯一方法是使用 XMLHttpRequest 对象.

The only way to make such a request from a web page is to use the XMLHttpRequest object.

Google 提供 一个 JavaScript 库(包装 XMLHttpRequest)可以与他们的 URL Shortener API 进行交互.

Google provide a JavaScript library (which wraps XMLHttpRequest) that can interact with their URL Shortener API.

这篇关于发布请求以包含“内容类型"和 JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆