Skip to content

Instantly share code, notes, and snippets.

@ayatmaulana
Created March 6, 2018 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayatmaulana/960f060eef5d4974d603030b92383a8d to your computer and use it in GitHub Desktop.
Save ayatmaulana/960f060eef5d4974d603030b92383a8d to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
// "io/ioutil"
_"reflect"
"encoding/json"
// "log"
// "decoder/json"
)
var
type Response struct {
Simsimi_talk_set Talk
IsFilter int `json:isFilter`
}
type Talk struct {
Id int `json:id`
Rid int `json:rid`
Message Message
Answer string `json:answer`
Lc string `json:lc`
TeacherUid int `json:teacher_uid`
ReportCnt int `json:reportCnt`
Type int `json:type`
BoostRemainQuota int `json:boostRemainQuota`
Answers []Answers
}
type Answers struct {
Id int `json:id`
SenderId int `json:sender_id`
Sentence string `json:sentence`
Timestamps int64 `json:timestamps`
Type string `json:type`
Metadata string `json:metadata`
ReceiverNickname string `json:receiver_nickname`
}
type Message struct {
Id int `json:id`
Sender_id string `json:sender_id`
Sentence string `json:sentence`
Timestamps int64 `json:timestamps`
Type string `json:type`
Metadata string `json:metadata`
ReceiverNickname string `json:receiver_nickname`
}
func main() {
url := "http://www.simsimi.com/otn/talk?talkCnt=2&reqText=halo"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
req.Header.Add("Accept-Encoding", "gzip, deflate")
req.Header.Add("Accept-Language", "id,en;q=0.9")
req.Header.Add("Cache-Control", "no-cache")
req.Header.Add("Connection", "keep-alive")
req.Header.Add("Cookie", "dotcom_session_key=s%3ADZ2djqlVs-DGk8ytAf_E9x5dkENoHdkd.TN6hQ6oAEUCn4QPgwdMXqIKsdyJLSgK9gysai%2FDcxvs; _ga=GA1.2.1691868767.1519388238; _gid=GA1.2.1941626242.1519388238; io=pA8546xih6_1zXoyAAzX")
req.Header.Add("Host", "www.simsimi.com")
req.Header.Add("If-None-Match", "W/\"1f5-ydvijGdp6ZVzqp4n2nbIlw\"")
req.Header.Add("Upgrade-Insecure-Requests", "1")
req.Header.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 YaBrowser/18.1.1.841 Yowser/2.5 Safari/537.36")
req.Header.Add("Postman-Token", "781051d3-b97b-4e82-ac34-146e5bb9cbac")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
// body, _ := ioutil.ReadAll(res.Body)
// resString := &Response{}
// err := json.Unmarshal([]byte(res.String()), resString)
// fmt.Println(resString)
// if err != nil {
// log.Fatal(err)
// }
// fmt.Println(reflect.TypeOf(res))
// fmt.Println(string(body))
var u Response
if res.Body == nil {
//http.Error(w, "Please send a request body", 400)
fmt.Println("error")
return
}
err := json.NewDecoder(res.Body).Decode(&u)
fmt.Println(u)
if err != nil {
// http.Error(w, err.Error(), 400)
fmt.Println( err.Error() )
return
}
fmt.Println(u)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment