"함수 getTextFromURL()"의 두 판 사이의 차이

 
(같은 사용자의 중간 판 12개는 보이지 않습니다)
42번째 줄: 42번째 줄:
==Java==
==Java==
[[분류: Java]]
[[분류: Java]]
<syntaxhighlight lang='java'>
<syntaxhighlight lang='java' run>
URL url = new URL("https://raw.githubusercontent.com/jmnote/test1/master/utf8test.txt");
import java.io.IOException;
Scanner scanner = new Scanner(url.openStream(), "UTF-8");
import java.net.URL;
scanner.useDelimiter("\\A");
import java.util.Scanner;
String content = scanner.next();
 
scanner.close();
class App {
System.out.println(content);
    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);
    }
}
 
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='java'>
<syntaxhighlight lang='java' run>
URL url = new URL("https://raw.githubusercontent.com/jmnote/test1/master/utf8test.txt");
import java.io.BufferedReader;
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
import java.io.IOException;
String line;
import java.io.InputStreamReader;
String content = "";
import java.net.URL;
while ((line = in.readLine()) != null) content += line + System.getProperty("line.separator");
 
System.out.println(content);
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);
    }
}
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='java'>
<syntaxhighlight lang='java' run>
URL url = new URL("https://raw.githubusercontent.com/jmnote/test1/master/utf8test.txt");
import java.io.BufferedReader;
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
import java.io.IOException;
String line;
import java.io.InputStreamReader;
List<String> lines = new ArrayList<String>();
import java.net.URL;
while ((line = in.readLine()) != null) lines.add(line);
import java.util.ArrayList;
String content = String.join(System.getProperty("line.separator"), lines);
import java.util.List;
System.out.println(content);
 
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);
    }
}
</syntaxhighlight>
</syntaxhighlight>


==JavaScript==
==JavaScript==
[[category: JavaScript]]
[[category: JavaScript]]
<syntaxhighlight lang='JavaScript'>
<syntaxhighlight lang='JavaScript' run>
fetch('https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version')
    .then(response => response.text())
    .then(text => console.log(text));
</syntaxhighlight>
<syntaxhighlight lang='JavaScript' run>
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');
</syntaxhighlight>
<syntaxhighlight lang='JavaScript' run>
var xhr = new XMLHttpRequest();
var xhr = new XMLHttpRequest();
xhr.open("GET",'https://raw.githubusercontent.com/jmnote/test1/master/utf8test.txt',false);
xhr.open("GET",'https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version',false);
xhr.send();
xhr.send();
console.log( xhr.responseText );
console.log( xhr.responseText );
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='JavaScript'>
<syntaxhighlight lang='JavaScript' run>
function file_get_contents(url) {
function getTextFromURL(url) {
var xhr = new XMLHttpRequest();
const xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
xhr.open("GET", url, false);
xhr.send();
xhr.send();
return xhr.responseText;
return xhr.responseText;
}
}
console.log( file_get_contents('https://raw.githubusercontent.com/jmnote/test1/master/utf8test.txt') );
console.log( getTextFromURL('https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version') );
</syntaxhighlight>
</syntaxhighlight>


129번째 줄: 171번째 줄:
contents = h.read
contents = h.read
print contents
print contents
</syntaxhighlight>
==UnityScript==
[[category: UnityScript]]
<syntaxhighlight lang='javascript'>
var www:WWW = new WWW("https://raw.githubusercontent.com/jmnote/test1/master/utf8test.txt");
yield www;
Debug.Log(www.text);
</syntaxhighlight>
</syntaxhighlight>



2023년 4월 15일 (토) 22:23 기준 최신판

1 개요[ | ]

함수 getTextFromURL()
함수 get_http_content()

2 Bash[ | ]

content=$(curl -s https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version)
echo content=[$content]

3 Go[ | ]

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)
}

4 Java[ | ]

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);
    }
}
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);
    }
}
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);
    }
}

5 JavaScript[ | ]

fetch('https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version')
    .then(response => response.text())
    .then(text => console.log(text));
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');
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 );
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') );

6 Objective-C[ | ]

//  ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <NSURLConnectionDelegate> {
    NSURLConnection* urlconn;
}
@end
//  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
$content = file_get_contents('https://raw.githubusercontent.com/kubernetes/kubernetes/v1.26.3/.go-version');
var_dump($content);

8 Ruby[ | ]

require 'open-uri'
h = open('https://raw.githubusercontent.com/jmnote/test1/master/utf8test.txt);
contents = h.read
print contents

9 UnityScript[ | ]

var www:WWW = new WWW("https://raw.githubusercontent.com/jmnote/test1/master/utf8test.txt");
yield www;
Debug.Log(www.text);

10 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}