【发布时间】:2021-04-07 17:35:14
【问题描述】:
我正在尝试向 tinyURL 发出获取请求,特别是发布请求,以缩短在我的网站上生成的 url。这是 tinyURL API
目前,我正在编写这样的代码,但它似乎没有返回短网址。
tinyurl 这个词似乎在链接中被禁止,所以所有链接 包含单词 tinyurl 已替换为“SHORT”
这是 tinyURL API https://SHORT.com/app/dev
import * as React from 'react'
interface tinyURlProps { url: string } export const useTinyURL = ({ url }: tinyURlProps) => { React.useEffect(() => {
const apiURL = 'https://api.SHORT.com/create'
const data = JSON.stringify({ url: url, domain: 'tiny.one' })
const options = {
method: 'POST',
body: data,
headers: {
Authorization:
'Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
Accept: 'application/json',
'Content-Type': 'application/json',
},
} as RequestInit
fetch(apiURL, options)
.then((response) => console.log(response))
.then((error) => console.error(error))
console.log('TinyUrl ran') }, [url])
}
【问题讨论】:
-
这是your other question 的旧版本吗?如果是这样,请删除这个。如果不是,请编辑其中一个问题,以便与另一个问题清楚地区分。
-
这两个问题几乎是一样的,只问了5分钟?为什么?
-
it doesn't appear to be returning the short url那么它在做什么呢? -
我的错误我认为这个版本没有发布它返回我输入的代码和消息和错误,我将删除其他
-
@IanKemp 这是我收到的回复imgur.com/VK4ISDg
标签: javascript reactjs typescript api fetch