1 개요[ | ]
- 함수 getTextFromURL()
- 함수 get_http_content()
2 Bash[ | ]
Bash
Copy
content=$(curl -s https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version)
echo content=[$content]
Loading
3 Go[ | ]
Go
Copy
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func getHTTPContent(url string) string {
resp, err := http.Get(url)
if err != nil {
return ""
}
defer resp.Body.Close()
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return ""
}
return string(bodyBytes)
}
func main() {
content := getHTTPContent("https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version")
fmt.Println(content)
}
Loading
4 Java[ | ]
Java
Copy
import java.io.IOException;
import java.net.URL;
import java.util.Scanner;
class App {
public static void main(String args[]) throws IOException {
URL url = new URL("https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version");
Scanner scanner = new Scanner(url.openStream(), "UTF-8");
scanner.useDelimiter("\\A");
String content = scanner.next();
scanner.close();
System.out.println(content);
}
}
Loading
Java
Copy
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
class App {
public static void main(String args[]) throws IOException {
URL url = new URL("https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
String content = "";
while ((line = in.readLine()) != null) content += line + System.getProperty("line.separator");
System.out.println(content);
}
}
Loading
Java
Copy
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
class App {
public static void main(String args[]) throws IOException {
URL url = new URL("https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
List<String> lines = new ArrayList<String>();
while ((line = in.readLine()) != null) lines.add(line);
String content = String.join(System.getProperty("line.separator"), lines);
System.out.println(content);
}
}
Loading
5 JavaScript[ | ]
JavaScript
Copy
fetch('https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version')
.then(response => response.text())
.then(text => console.log(text));
▶ | 1.19.7 |
JavaScript
Copy
const fetchText = async function(url) {
const response = await fetch(url);
const data = await response.text();
console.log( data );
};
fetchText('https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version');
▶ | 1.19.7 |
JavaScript
Copy
var xhr = new XMLHttpRequest();
xhr.open("GET",'https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version',false);
xhr.send();
console.log( xhr.responseText );
▶ | 1.19.7 |
JavaScript
Copy
function getTextFromURL(url) {
const xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
xhr.send();
return xhr.responseText;
}
console.log( getTextFromURL('https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version') );
▶ | 1.19.7 |
6 Objective-C[ | ]
Objective-C
Copy
// ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <NSURLConnectionDelegate> {
NSURLConnection* urlconn;
}
@end
Objective-C
Copy
// ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
urlconn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://raw.githubusercontent.com/jmnote/test1/master/utf8test.txt"]] delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}
@end
7 PHP[ | ]

PHP
Copy
<?php
$content = file_get_contents('https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version');
var_dump($content);
Loading
8 Ruby[ | ]
Ruby
Copy
require 'open-uri'
h = open('https://raw.githubusercontent.com/jmnote/test1/master/utf8test.txt);
contents = h.read
print contents
9 UnityScript[ | ]
JavaScript
Copy
var www:WWW = new WWW("https://raw.githubusercontent.com/jmnote/test1/master/utf8test.txt");
yield www;
Debug.Log(www.text);
10 같이 보기[ | ]
로그인하시면 댓글을 쓸 수 있습니다.
HTML textarea 자동 높이 조절 ― …JavaScript 랜덤 한글 ― JmnoteJavaScript 랜덤 한글 ― JmnoteJavaScript 랜덤 한글 ―Pinkcrimson
JavaScript 랜덤 한글 ― MywikierJavaScript 변수 ― Nathan on zetawikiJavaScript 변수 ― John JeongJavaScript 변수 ― SotoZeroClipboard 사용하기 ― LilisZeroClipboard 사용하기 ― Jmnote자바스크립트 HTML 테이블 행 추가/삭제 ― Pilming자바스크립트 HTML 테이블 행 추가/삭제 ― Jmnote자바스크립트 웹페이지 읽기 ― …